SQL ALTER TABLE Statement


The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table. The where clause specifies which record or records that should be updated.

ALTER TABLE – ADD Column
To add a column in a table, use the syntax:
 ALTER TABLE table_name
   ADD column_name datatype;

The SQL adds an Email column to the Customers table:
 ALTER TABLE Customers
   ADD Email VARCHAR(255);


ALTER TABLE – DROP COLUMN
To delete a column in a table, use the syntax:
 ALTER TABLE table_name
   DROP COLUMN column_name;

The SQL deletes an Email column from the Customers table:
 ALTER TABLE Customers
   DROP COLUMN  Email;


ALTER TABLE – ALTER/MODIFY COLUMN

To change the data type of a column in a table, use the syntax:
 ALTER TABLE table_name
   MODIFY column_name datatype;



Demonstration
Below is an SQL test area from W3Schools, which uses the well-known Northwind sample database. The tables here are for read only because of the problem of embedding the scripts. For a fully working example, check this by using Chrome.

SQL Statement:

Edit the SQL statement and click     to see the result, or  

Result:
The Database includes:
The Database includes:

TablenameRecord
Customers91
Categories8
Employees10
OrderDetails518
Orders196
Products77
Shippers3
Suppliers29




      You only get one bite at the cherry (good opportunity) in life.