Introduction:

In this article we will explain how to alter a table in SQL Server or how to rename column name or change column data type by using alter table statement in SQL Server with Example.

Description:

The ALTER TABLE statement is used to add, modify or delete columns in an existing table. It is also used to rename a table.

You can also use SQL ALTER TABLE command to add and drop various constraints on an existing table.


  • SQL ALTER TABLE Add Column

If you want to add columns in SQL table, to use the following SQL alter table syntax:

ALTER TABLE table_name ADD column_name datatype;


Example:

ALTER TABLE employee ADD Address nvarchar(500);

 


  • SQL ALTER TABLE Modify Column

If you want to modify an existing column data type in SQL table, to use the following SQL alter table syntax:

ALTER TABLE table_name ALTER COLUMN column_name datatype;

 

Example:

 

 

ALTER TABLE employee ALTER COLUMN Address nvarchar(750); 

 


  • SQL ALTER TABLE DROP Column


If you want to delete an existing column in SQL table, to use the following SQL alter table syntax:

ALTER TABLE table_name DROP COLUMN column_name;  

Example:

ALTER TABLE employee DROP COLUMN Address;

I hope this article will help to you.

comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like