Strange behavior when renaming a column in SQL Server 2008

I need to write code to rename a column in SQL Server 2008.
When writing scripts in Management Studio, I got a double rename:

NAME1 ==> TEMPNAME ==> NAME2

BEGIN TRANSACTION GO EXECUTE sp_rename 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 at a time, it works just fine.

Why is the first column renamed to a temporary name? Does it make sense to code a renaming algorithm to do the same?

Thanks!

+7
sql-server-2008 ssms
source share
1 answer

You can change the column names between two columns. Management Studio maintains this by renaming all columns to temporary names and then renaming them to final names.

Blorgbeard: in the context menu "Design Window" there is a choice of change script.

+6
source share

All Articles