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.
Author |
Topic |
Jdang67
Starting Member
3 Posts |
Posted - 2009-08-06 : 09:05:35
|
Hi allCan we used alter table to rename table or column in sqlserver 2005 now? If yes then what is the syntax? I know we have sp_rename procedure but this one is unclear.Regards,Jdang |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-08-06 : 09:18:30
|
Why is sp_rename unclear?!?sp_rename [ @objname = ] 'object_name' , [ @newname = ] 'new_name' [ , [ @objtype = ] 'object_type' ]So, for a table name change:sp_rename 'database.testtbl', 'newtesttbl';for a column name change:sp_rename 'datasbase.table.oldcolname', 'newcolname', 'COLUMN';Couldn't be easier.. |
|
|
Jdang67
Starting Member
3 Posts |
Posted - 2009-08-06 : 09:28:28
|
Well you need to remember all parameters or you need to read the document. To me Alter table AAA rename to BBB Oralter table AAA alter column a1 rename to a2are much better and much easier and I do not need to remember anything.Jdang |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-08-06 : 10:52:03
|
Why is that easier? It is more convoluted and you need to ensure you start in the correct database, so you would need a USE at the top of the statement.I fail to see how it is convoluted in the slightest. It just uses 3 part naming conventions. |
|
|
|
|
|