SQL ALTER TABLE

SQL ALTER TABLE

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. It is also used to add and drop various constraints on an existing table.


Add a Column

To add a new column to a table, use the following syntax:

ALTER TABLE table_name
ADD column_name datatype;

Example

ALTER TABLE ADD Example

ALTER TABLE Customers
ADD Email varchar(255);

Drop a Column

To delete an existing column from a table, use the following syntax:

ALTER TABLE table_name
DROP COLUMN column_name;

Modify a Column's Data Type

The syntax to change the data type of a column varies between database systems.

SQL Server / MS Access Syntax

ALTER TABLE table_name
ALTER COLUMN column_name new_datatype;

MySQL / Oracle Syntax

ALTER TABLE table_name
MODIFY COLUMN column_name new_datatype;