How to add, rename, and drop Column

By Sandeep Singh Shekhawat Jan 02, 2013
In this blog I am going to explain that how can do add, rename and drop a column from a table.

1.       Create a Table

CREATE TABLE STUDENT

(

          Id int Identity(1,1),

          Name varchar(10)

)

  2.       Insert a Row

INSERT INTO STUDENT VALUES('XYZ')

3.       Show Data 

SELECT * FROM STUDENT

1.PNG

4.       Add a New Column 

ALTER TABLE STUDENT

       ADD  Address VARCHAR(50)

 

       SELECT * FROM STUDENT

 

2.png 


5.       Modify Column Type 

Here I am going to Modify Address Column from VARCHAR(50) to  NVARCHAR(50)

ALTER TABLE STUDENT

       ALTER COLUMN Address NVARCHAR(50)

6.       Rename a Column

sp_rename 'STUDENT.Address','Stu_Address','COLUMN'

SELECT * FROM STUDENT

 

3.png

7.       Drop a Column 

ALTER TABLE STUDENT

       DROP COLUMN Stu_Address

Sandeep Singh Shekhawat

Sandeep Singh Shekhawat is a Software Developer. He is awarded for C# Corner MVP(2013,2014 and 2015) and CodeProject MVP (2015). His three articles at CodeProject are prize wining in article competition. His more ... Read more

COMMENT USING