The ALTER TABLE command is used to manage columns in a table.
To add a column use the ADD option.
To change a column use the ALTER option.
To remove a column use the DROP option.
This example adds an Email column to the Supplier table.
ALTER TABLE Supplier
ADD Email NVARCHAR(60)
Syntax to add a column.
ALTER TABLE table-name ADD column-name data-type
Syntax to change a column. Effectively, this changes the data type.
ALTER TABLE table-name ALTER COLUMN column-name data-type
Syntax to remove (drop) a column.
ALTER TABLE table-name DROP COLUMN column-name
SUPPLIER |
---|
Id |
CompanyName |
ContactName |
City |
Country |
Phone |
Fax |
ALTER TABLE Supplier
ALTER COLUMN CompanyName NVARCHAR(100)
SUPPLIER |
---|
Id |
CompanyName |
ContactName |
City |
Country |
Phone |
Fax |
ALTER TABLE Supplier
DROP COLUMN Fax