开发者

Strange behaviour when renaming a column in SQL Server 2008

I need to write some code for renaming a column in SQL Server 2008.

When scripting that in Management Studio I got a double renaming :

NAME1 ==> TEMPNAME ==> NAME2

BEGIN TRANSACTION
GO
EXECUTE sp_rename 开发者_JAVA百科N'dbo.Table_1.columFirstName', N'Tmp_columSecondName_2', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.Table_1.Tmp_columSecondName_2', N'columSecondName', 'COLUMN' 
GO
ALTER TABLE dbo.Table_1 SET (LOCK_ESCALATION = TABLE)
GO
COMMIT

But when I do it in one go, It works just fine.

Why the column first is renamed to a temporary name? Does it makes sense when coding a renaming algoritm to do the same?

Thanks!


You can swap column names between two columns. Management studio supports that by renaming all columns to temporary names, and then renaming them to the final names.

Blorgbeard: In the Design Window right-click menu, there is a generate change script choice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜