Add Clause: Columns
- Last Updated: May 15, 2020
- 1 minute read
- DataDirect Connectors
- JDBC
- IBM Db2 5.1
- MySQL 5.1
- Progress OpenEdge 5.1
- SAP Sybase 5.1
- Documentation
Purpose
Adds a column to an existing table. It is optional. The column is added to the end of the column list.
Syntax
ADD [COLUMN] column_name Datatype ...
[BEFORE existing_column]
Notes
- If
NOT NULLis specified and the table is not empty, a default value must be specified. In all other respects, this command is the equivalent of a column definition in a Create Table statement. - You cannot specify ANYTYPE, BINARY, COMBOBOX, or TIME data types in the column definition of Alter Table statements.
- Using the
Beforeexisting_column clause, you can specify the name of an existing column so that the new column is inserted in a position just before the existing column. - If a SQL view includes
SELECT * FROMfor the table to which the column was added in the view’s Select statement, the new column is added to the view.
Example A
Assuming the current schema is PUBLIC, this example adds the status column
with a default value of ACTIVE to the test table.
ALTER TABLE test ADD COLUMN status VARCHAR(30) DEFAULT 'ACTIVE'
Example B
Assuming the current schema is PUBLIC, this example adds a deptId column
that can be used as a foreign key column.
ALTER TABLE test ADD COLUMN deptId INT