Thursday 4 December 2014

The ALTER TABLE Statement

The ALTER TABLE Statement

ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

To add a column in a table

Syntax : 

alter tablename add column columnname datatype 

Example: 

alter empdetails add column city varchar (50)

To delete a column in a table

Syntax : 

alter table tablename drop column columnname

Example: 

alter table empdetails drop column city 

To change the data type of a column in a table

Syntax : 

alter table tablename alter column columnname datatype

Example: 

alter table empdetails alter column salary varchar(50)

Note:

 We cannot change a character datatype of a column to int , varchar , nvarchar after the table has been inserted with values.












No comments:

Post a Comment