Make copies of your baseball tables

  1. First we will look at making a copy of our baseball tables, so we don't mess up the originals. The basic syntax is
CREATE TABLE <NEW TABLE name>
AS (SELECT * FROM <old TABLE name>)
  1. The second line is a subquery, we will talk more about these later.
    1. Here is the statement to copy the stadium table.
    CREATE TABLE copy_stadiums
    AS (SELECT * FROM stadiums)
    1. If you SELECT * FROM copy_stadiums, you will see that the data was copied into the new table
    2. Repeat with the other three columns of the baseball tables, check each copy with a SELECT *

ALTER TABLE - Remember, ALTER lets you change the properties of column

ALTER TABLE <TABLE name>
ADD (<COLUMN name> <data type>)
  1. ADD a stadium_name column to the teams table, then use the UPDATE command (from the CRUD lesson) to populate the new column NOTE: This is the only time this lesson you should change the base table and not the copy
  2. MODFY the copy_teams table's mascot column to be VARCHAR2(50)
  3. DROP the the stadiums column from the copy_game table

DROP TABLE

DROP TABLE <TABLE name>
  1. Remember you can't always undo a drop, so use this carefully
  2. DROP the copy_sections table

TRUNCATE TABLE
  1. Truncate is for removing all the data from a table, a leaving just the table structure
  2. TRUNCATE copy_stadium table

Call me over to check your work