Rommel20
Rommel20

Reputation: 119

Renaming of Table

I am using sp_rename to switch table name , below is my query

exec sp_rename 'dbo.People_Daily' , 'TEMP'
exec sp_rename 'dbo.People_Future', 'People_Daily'
exec sp_rename 'TEMP',   'dbo.People_Future'

My questions is, what if I execute the same query in parallel with different table name,since im using TEMP word in both query, is there a possiblity that the TEMP in People will be used by Address?, what should I do to avoid this, is there any auto generated word to replace TEMP?

exec sp_rename 'dbo.Address_Daily' , 'TEMP'
exec sp_rename 'dbo.Addresse_Future', 'Address_Daily'
exec sp_rename 'TEMP',   'dbo.Address_Future'

Thanks!!!

Upvotes: 0

Views: 118

Answers (1)

miroxlav
miroxlav

Reputation: 12204

Using TEMP can collide if your batches run in parallel. But you can use TEMP as an suffix to existing table name:

exec sp_rename 'dbo.People_Daily' , 'dbo.People_Daily_TEMP'
exec sp_rename 'dbo.People_Future', 'People_Daily'
exec sp_rename 'dbo.People_Daily_TEMP',   'dbo.People_Future'

and

exec sp_rename 'dbo.Address_Daily' , 'dbo.Address_Daily_TEMP'
exec sp_rename 'dbo.Addresse_Future', 'Address_Daily'
exec sp_rename 'dbo.Address_Daily_TEMP',   'dbo.Address_Future'

Then your batches won't collide.

Upvotes: 3

Related Questions