SQL ALTER TABLE

The SQL ALTER TABLE command is used to add, delete or modify columns in an existing table.
use ALTER TABLE command to add and drop various constraints on a an existing table.

SYNTAX:

ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};

ALTER TABLE to add a new column in an existing table is
ALTER TABLE table_name ADD column_name datatype;

ALTER TABLE to DROP COLUMN in an existing table is
ALTER TABLE table_name DROP COLUMN column_name;

ALTER TABLE to change the DATA TYPE of a column in a table is
ALTER TABLE table_name MODIFY COLUMN column_name datatype;

EXAMPLE:

ALTER TABLE CUSTOMERS ADD GENDER char(1);
Adds a new column GENDER to the table CUSTOMERS.

ALTER TABLE CUSTOMERS DROP GENDER;
Deletes the column GENDER from the table CUSTOMERS.

No comments:

Post a Comment