SQL ALTER TABLE

SQL ALTER TABLE  is used to add, delete, or modify columns in a table .

Add columns

Syntax

ALTER TABLE table_name ADD column_name datatype

Example

mysql> ALTER TABLE orders  ADD price int ;
Query OK, 0 rows affected (0.11 sec)
Records: 0  Duplicates: 0  Warnings: 0

Delete columns

Syntax

ALTER TABLE table_name DROP COLUMN column_name

Example

mysql> ALTER TABLE orders DROP COLUMN price;
Query OK, 1 row affected (0.09 sec)
Records: 1  Duplicates: 0  Warnings: 0

Modify columns

Syntax

ALTER TABLE table_name CHANGE column_name column_name datatype

Example

mysql> ALTER TABLE  orders CHANGE  items  items VARCHAR( 255 );
Query OK, 0 rows affected (0.09 sec)
Records: 0  Duplicates: 0  Warnings: 0