Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 rename column failed

Author  Topic 

shubhada
Posting Yak Master

117 Posts

Posted - 2006-02-16 : 02:13:03
I am trying to rename the column name with new name of existing table using followig syntax

ALTER TABLE test1 RENAME COLUMN total to sum
but i got the following error.

Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'COLUMN'.

please tell me how I can rename the column.

shubhada

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2006-02-16 : 02:23:05
Hi shubhada,
Use
sp_rename 'table.columnname','newname','Column'
Pls make sure that references to the column are also been updated.
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2006-02-16 : 02:27:42
also, avoid using reserved words for column and table names.



-ec
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-16 : 03:07:58
Also, if possible you can keep the column as it is and use alias name when querying

Select total as NewAliasName from yourTable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -