SQL ALTER

SQL ALTER is used to add, modify and remove the columns of Existing Table. It is also used to Rename the table.

 

SQL ALTER ADD

If you want to add a column to the table SQL ALTER TABLE Syntax is below:

ALTER TABLE table_name ADD column1 data type.

 

If you want to add multiple columns then the syntax is:

ALTER TABLE table_name
ADD (Column1 data type,
Column2, data type,
Column3, data type…
);

 

Example:

ALTER TABLE Student ADD Age Integer;

 

Age column will be added to Student Table.

StudentID Student_Name Address City
       

 

SQL ALTER MODIFY

If you want to modify the Single column the syntax is below:

ALTER TABLE table_name MODIFY column_name data type;

 

If you want to modify multiple columns the syntax is

ALTER TABLE table_name
MODIFY (Column1 data type,
Column2, data type,
Column3, data type…
);

 

SQL ALTER TABLE DROP

The syntax of ALTER TABLE DROP is:

ALTER TABLE table_name DROP COLUMN column_name;

 

It will drop the column from the table.

Example:

ALTER TABLE Student DROP Age

 

The Age column will be dropped from the table.

StudentID Student_Name Address City

 

SQL ALTER RENAME

The ALTER RENAME Syntax is as follows:

ALTER TABLE table_name RENAME COLUMN old_name to new_name;

 

Example

ALTER TABLE Student RENAME COLUMN StudentID to ID;

 

Now the column name will be renamed as ID

ID Student_Name Address City