ALTER

From SQLZOO
Jump to navigation Jump to search

ALTER TABLE

The table games shows the year and the city hosting the Olympic Games.

games
yrcity
2004Athens
2006Turin
schema:scott
 DROP TABLE games
 CREATE TABLE games(
  yr INTEGER PRIMARY KEY,
  city VARCHAR(20));
INSERT INTO games VALUES (2004,'Athens');
INSERT INTO games VALUES (2006,'Turin');

The ALTER statement can be used to add a column. In this example the column season indicates if the games are winter or summer games.

SELECT * FROM scott.games;
ALTER TABLE games ADD season VARCHAR(6);
UPDATE games SET season = 'summer'
  WHERE yr = 2004;
UPDATE games SET season = 'winter'
  WHERE yr = 2006;
SELECT * FROM scott.games;
SELECT * FROM games;
ALTER TABLE games ADD season VARCHAR(6);
UPDATE games SET season = 'summer'
  WHERE yr = 2004;
UPDATE games SET season = 'winter'
  WHERE yr = 2006;
SELECT * FROM games;

See also

Language:Project:Language policy English  • Deutsch
DataWars, Data Science Practice Projects - LogoDataWars: Practice Data Science/Analysis with +100 Real Life Projects