Blog

How to add, rename, and drop Column

Posted 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

post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts