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

From SQLZOO
Jump to: navigation, search
 
(One intermediate revision by one user not shown)
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>
  
 
<div class="ecomm e-db2" style="display: none">
 
<div class="ecomm e-db2" style="display: none">
<a href="https://aurora.vcu.edu/db2help/db2s0/frame3.htm#sqls0604">
+
[https://aurora.vcu.edu/db2help/db2s0/frame3.htm#sqls0604 ALTER TABLE documentation.]
ALTER TABLE documentation.</a>
+
 
DB2 seemingly does not permit this operation - any help would be appreciated.
 
DB2 seemingly does not permit this operation - any help would be appreciated.
 
</div>
 
</div>
Line 27: Line 28:
 
</div>
 
</div>
 
<div class="ecomm e-postgres" style="display: none">
 
<div class="ecomm e-postgres" style="display: none">
<a href="http://www.ca.postgresql.org/users-lounge/docs/7.0/user/sql-altertable.htm">ALTER TABLE</a>
+
[http://www.ca.postgresql.org/users-lounge/docs/7.0/user/sql-altertable.htm ALTER TABLE]
 
</div>
 
</div>
 
</div>
 
</div>
 +
 
{{CREATE and DROP ref}}
 
{{CREATE and DROP ref}}

Latest revision as of 10:05, 18 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