Rename column name in SQL Server 2008/2005

Friday, June 19, 2009 |

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

0 comments: