Difference between revisions of "ALTER"

From SQLZOO
Jump to: navigation, search
Line 1: Line 1:
 
+
[[File:C:\Users\mn33894\Desktop\Subbu.jpeg]]
 
<h1>ALTER TABLE</h1>
 
<h1>ALTER TABLE</h1>
 
<p>The table <code>games</code> shows the year and the city hosting the Olympic Games.</p>
 
<p>The table <code>games</code> shows the year and the city hosting the Olympic Games.</p>

Revision as of 07:39, 9 May 2013

File:C:\Users\mn33894\Desktop\Subbu.jpeg

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