Tuesday, March 20, 2012

Rename a column

Is it safe to use DBCC RENAMECOLUMN(@.table, @.oldname, @.newname)
or is better to drop the column and recreate it?
Thanks in advance?DBCC RENAMECOLUMN is undocumented so the answer is, no, it is not
"safe".
In SQL Server 7.0 and 2000 use sp_rename to rename a column. No need to
drop and re-create it.
David Portas
SQL Server MVP
--|||Since that's undocumented, why not try sp_rename:
exec sp_rename 'tbl.ColOldName', 'ColNewName', 'column'
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"x-rays" <xrays@.discussions.microsoft.com> wrote in message
news:F190B789-8C8F-4FFE-8581-AE2641792F75@.microsoft.com...
> Is it safe to use DBCC RENAMECOLUMN(@.table, @.oldname, @.newname)
> or is better to drop the column and recreate it?
> Thanks in advance?|||Hi
DBCC RENAMECOLUMN is not documented, so don't use it.
Rather use sp_rename.
Regards
Mike
"x-rays" wrote:

> Is it safe to use DBCC RENAMECOLUMN(@.table, @.oldname, @.newname)
> or is better to drop the column and recreate it?
> Thanks in advance?|||Yeah, sure I can use sp_rename, thank you all replying.
"x-rays" wrote:

> Is it safe to use DBCC RENAMECOLUMN(@.table, @.oldname, @.newname)
> or is better to drop the column and recreate it?
> Thanks in advance?|||You should be very careful when renaming columns as you could break existing
views, stored procedures and user defined functions if any of these objects
use the column.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Database change management for SQL Server
"x-rays" wrote:
> Yeah, sure I can use sp_rename, thank you all replying.
> "x-rays" wrote:
>

No comments:

Post a Comment