SQL – Alter Table

SQL – Alter Table is DDL (Data definition language) statement.The ALTER TABLE command is used to modify the definition (structure) of a table by modifying the definition of its columns.It is used to add, delete or modify columns in an existing table.

Alter Table Statement :

  • Add a new column to a table
  • Drop a column from a table
  • Add a new table constraint
  • Drop a table constraint
  • Set a default for a column
  • Drop a default for a column

Syntax For ALTER TABLE :

To add a column in a table, syntax is as below:

ALTER TABLE table_name
ADD column_name datatype

For Example: To add a column “Student_ID” to the Student table, the query would be like-
ALTER TABLE Student ADD Student_Id number(3);

To delete a column in a table, syntax is as below: :

ALTER TABLE table_name
DROP COLUMN column_name

For Example: To drop the column “Country” from the Location table, the query would be like –
ALTER TABLE Location DROP Country;

To change the data type of a column in a table, syntax is as below:

ALTER TABLE table_name
ALTER COLUMN column_name datatype

For Example: To modify the column salary in the employee table, the query would be like –
ALTER TABLE employee ALTER COLUMN salary number(10,2);

Read Here – SQL – CREATE TABLE

Add a Comment

Your email address will not be published. Required fields are marked *