How can rename to objects in MSSqlServer

SQL SERVER – How to Rename a Column Name or Table Name Or StoreProcedure Name

The script for renaming any column

sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'

The script for renaming any object (table, sp etc)
sp_RENAME '[OldTableName]' , '[NewTableName]'

Create table tbemp(empno int,ename varchar(20))

Insert into tbemp(empno,ename) values(1,’Aryan’)

Insert into tbemp(empno,ename) values(1,’Bharat’)

Insert into tbemp(empno,ename) values(1,’Sukhpal’)

Select *from tbemp

Now  Change Column name empname to Name

sp_RENAME ‘tbemp.empname’, ‘Name’ , ‘COLUMN’

Now Execute this given below command see the result

Select *From tbemp

be happy and Enjoy in programming world……..

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s