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

#rename-sql-object