Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

SQL Add Column

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.

Example

#

This example adds an Email column to the Supplier table.

ALTER TABLE Supplier
  ADD Email NVARCHAR(60)

Syntax

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
  

More Examples

ALTER TABLE. Change COLUMN

SUPPLIER
Id
CompanyName
ContactName
City
Country
Phone
Fax
Problem: Increase the size of CompanyName to 100 characters in the Supplier table.
ALTER TABLE Supplier
  ALTER COLUMN CompanyName NVARCHAR(100)
Result:  Column altered

ALTER TABLE. Drop COLUMN

SUPPLIER
Id
CompanyName
ContactName
City
Country
Phone
Fax
Problem: Remove the Fax column from the Supplier table.
ALTER TABLE Supplier
  DROP COLUMN Fax
Result:  Column dropped

You may also like



Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

Guides


vsn 3.1