skip to main content
Querying data stores with SQL : Supported SQL and Extensions : Alter Table for Salesforce : Add Clause: Columns
  

Try Now
Add Clause: Columns

Purpose

Supported only for Salesforce-based data stores. Adds a column to an existing table. This clause is optional.

Syntax

ADD [COLUMN] column_name Datatype ...
[DEFAULT default_value] [[NOT]NULL] [EXT_ID] [PRIMARY KEY]
[START WITH starting_value]
where:
default_value
specifies the default value to be assigned to the column. See Column Definition for details.
starting_value
specifies the starting value for the Identity column. The default start value is 0.

Notes

*If NOT NULL is 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.
*If a SQL view includes SELECT * FROM for 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 a schema named SFORCE, this example adds the status column with a default value of ACTIVE to the test table.
ALTER TABLE test ADD COLUMN status TEXT(30) DEFAULT 'ACTIVE'
The view selects the name column from both the opportunity and account tables. These columns are assigned the alias OpportunityName and AccountName, respectively.

Example B

Assuming a schema named SFORCE, this example adds a deptId column that can be used as a foreign key column.
ALTER TABLE test ADD COLUMN status TEXT(30) DEFAULT 'ACTIVE'