How to add, rename, and drop Column

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

Ebook Download
View all
Learn
View all