Blog

How to add, rename, and drop Column

By Sandeep Singh Shekhawat Blogs | SQL 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

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs