Difference between revisions of "ALTER TABLE ... ADD COLUMN"

From SQLZOO
Jump to: navigation, search
Line 13: Line 13:
 
</source>
 
</source>
  
<source lang='sql' class='def'>ALTER TABLE a ADD COLUMN z INTEGER
+
<source lang='sql' class='def'>ALTER TABLE a ADD COLUMN z INTEGER;
 +
SELECT * FROM a;
 
</source>
 
</source>
<source lang='sql' class='def e-sqlserver e-sybase'>ALTER TABLE a ADD z INTEGER
+
<source lang='sql' class='def e-sqlserver e-sybase'>ALTER TABLE a ADD z INTEGER;
 +
SELECT * FROM a;
 
</source>
 
</source>
  
Line 30: Line 32:
 
</div>
 
</div>
 
</div>
 
</div>
 +
 
{{CREATE and DROP ref}}
 
{{CREATE and DROP ref}}

Revision as of 15:10, 17 July 2012

Add a column to a table

schema:scott

This is in the SQL standard ALTER TABLE The term COLUMN is optional.

DROP TABLE a
CREATE TABLE a(x INTEGER, y INTEGER);
INSERT INTO a VALUES (1,2);
ALTER TABLE a ADD COLUMN z INTEGER;
SELECT * FROM a;
ALTER TABLE a ADD z INTEGER;
SELECT * FROM a;
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense