Difference between revisions of "ALTER"

From SQLZOO
Jump to: navigation, search
(Created page with " <h1>ALTER TABLE</h1> <p>The table <code>games</code> shows the year and the city hosting the Olympic Games.</p> <table> <caption align='center'>games</caption> <tr><th align=...")
 
(Undo revision 13160 by 180.211.64.153 (talk))
 
(2 intermediate revisions by 2 users not shown)
Line 45: Line 45:
 
   <li>[[DROP |DROP]]</li>
 
   <li>[[DROP |DROP]]</li>
 
</ul>
 
</ul>
 +
 +
{{Languages}}

Latest revision as of 15:22, 9 May 2013

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: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense