Rename the SQL object

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’))
Begin
Declare @SP varchar(1000)
Set @SP = ‘Bk_’ + CONVERT(VARCHAR(8), GETDATE(), 112) + ‘SQLObjectName’
EXEC sp_rename ‘SQLObjectName’, @SP
End

After execution of above SQL object would renamed to BK_YYYYMMDD_SQLObjectName.

 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s