Rename column name in SQL Server 2008/2005

Recently I have been asked that we can change the name of column from GUI easily but how can we do it from T-SQL. Well, this is very small thing but when I have been asked, it strikes in my mind that quite a few people doesn’t know this actually so I decided to write this very small script. This task is easiest stuff in T-SQL with the help of sp_rename system stored procedure
Have a look.
–Emps is a tablename
–Name is current column name in emp table
–want to give new name “Name11” to old name “Name” of emps table
–“Column” at last, is a key word which tells SQL Server that we
–want to change column name
EXEC sp_rename ’emps.[name]’, ‘Name11’, ‘COLUMN’
Reference: Ritesh Shah
http://www.sqlhub.com
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of
http://www.SQLHub.com
Advertisements

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

%d bloggers like this: