The Alter Table statement adds a column, removes a column, or redefines a column in a table. The table being altered can be either a remote or local table. A remote table is a Salesforce object and is exposed in the SFORCE schema. A local table is maintained by the driver and is local to the machine on which the driver is running. A local table is exposed in the PUBLIC schema.
table_name specifies an existing remote table.
add_clause specifies a column or a foreign key constraint to be added to the table. See
“Add Clause: Columns” and
“Add Clause: Constraints” for a complete explanation.
drop_clause specifies a column to be dropped from the table. See
“Drop Clause: Columns” for a complete explanation.
This clause adds a column to the table. It defines a column with the same syntax as the Create Table command (see
“Column Definition for Remote Tables”). 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.
default_value is the default value to be assigned to the column. See
“Column Definition for Remote Tables” for details.
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.
starting_value is the starting value for the Identity column. The default start value is
0.
Assuming the current schema is SFORCE, this example adds the status column with a default value of
ACTIVE to the
test table.
Assuming the current schema is SFORCE, a foreign key constraint is added to the deptId column of the
test table, referencing the
rowId of the
dept table. For the operation to succeed, the
dept table must be empty.
where column_name specifies an existing column in an existing table.
This example drops the status column. For the operation to succeed, the status column cannot have a constraint defined on it and cannot be used in a SQL view.
table_name specifies an existing local table.
add_clause specifies a column or constraint to be added to the table. See
“Add Clause: Columns” and
“Add Clause: Constraints” for a complete explanation.
drop_clause specifies a column or constraint to be dropped from the table. See
“Drop Clause: Columns” and
“Drop Clause: Constraints” for a complete explanation.
rename_clause specifies a new name for the table. See
“Rename Clause” for a complete explanation.
This clause adds a column to the end of the column list. It defines a column with the same syntax as the Create Table command (see
“Column Definition for Local Tables”). 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.
The optional Before existing_column can be used to 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 * FROM for the table to which the column was added in the view’s Select statement, the new column is added to the view.
Assuming the current schema is PUBLIC, this example adds the status column with a default value of
ACTIVE to the
test table.
where column_name specifies an existing column in an existing table.
This example drops the status column. For the operation to succeed, the status column cannot have a constraint defined on it and cannot be used in a SQL view.
constraint_name specifies an existing constraint.
where new_name specifies the new name for the table.