ALTER Command in SQL Syntax

ALTER Command in SQL:

In SQL, ALTER Command can be used to add columns to the table, change their sizes, change their data types or add or delete constraints. It is not a part of the CRUD operations. But it is an essential part of DDL commands. It can also be used with multiple Relational Database Management Systems (RDBMS). It has the following syntax:

ALTER TABLE  [Options];

ADD Option:

ADD keyword is used to add columns or constraints to the table. It has the following syntax:

ALTER TABLE EMPLOYEE ADD PHONE_NO CHAR (10);

The above statement will add a new column PHONE_NO to the EMPLOYEE table.

MODIFY Option:

The Modify option can change the data type, column width, and constraints of an existing column. It has the following syntax:

ALTER TABLE EMPLOYEE MODIFY EMP_NAME VARCHAR (25);

DROP Option:

To remove the constraints imposed can be used. It has the following syntax:

ALTER TABLE EMPLOYEE DROP CONSTRAINT PIN_CODE;