ALTER/de

From SQLZOO
< ALTER
Revision as of 17:53, 8 September 2012 by Peter (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

ALTER TABLE

Die Tabelle games enthält das Jahr (year) und den Ort (city) der Olympischen Spiele.

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');

Mit der Anweisung ALTER können Spalten hinzugefügt werden. Im Beispiel wird die Spalte season hinzugefügt, in der gespeichert wird, ob es sich um Sommer- oder Winterspiele handelt.

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;

Siehe auch

Sprache: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense