Changing a column name in SQL Server 2008

How to change a predefined column name to a new name.

eg: Column name is "Accounts" I want to change it to "A/c" 

alter table emp change Accounts .... [What's Next]

+8
sql sql-server sql-server-2008
source share
6 answers

You need to use the sp_rename command or use Management Studio to do it visually - make sure you do it in a quiet period and make sure that it was done in pre-production first with testing!

By the way, I would stay away from A / C - the slash sign is a separation of special meaning.

The documentation for sp_rename is here, example B is most suitable. http://msdn.microsoft.com/en-us/library/ms188351.aspx

+13
source share

script to rename any column:

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

(Note that you are not using screens in the second argument, surprisingly.)

script to rename any object (table, sp, etc.):

 sp_RENAME '[OldTableName]' , 'NewTableName' 

see here for more information

+18
source share

You can use sp_rename as:

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

as your code looks like this:

 sp_RENAME 'table.Accounts','Acc','COLUMN' 
0
source share

Here is the code for sp_rename

 sp_RENAME 'emp.Accounts' , 'Acc' 

I used something like this and worked

0
source share
 sp_rename 'table_name.accounts', 'A/C', 'column' 

This request will solve your problem.

0
source share

The command to rename any column name:

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

It works without using the third column argument at the end.

0
source share

All Articles