Rename the SQL object   Leave a comment

Below is the SQL statement to search for the object in selected database and rename it with current date as prefix along with “BK_” word. Date format is “YYYYMMDD”.

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N’SQLObjectName’))
Declare @SP varchar(1000)
Set @SP = ‘Bk_’ + CONVERT(VARCHAR(8), GETDATE(), 112) + ‘SQLObjectName’
EXEC sp_rename ‘SQLObjectName’, @SP

After execution of above SQL object would renamed to BK_YYYYMMDD_SQLObjectName.



Posted September 26, 2014 by Izharuddin Shaikh in SQL

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: