Rename a table with sp_rename (Table name has square brackets in the name literal)


  
  
 CREATE TABLE [TEST].[[TEST]].[NewTableName](
 [StatusID] [int] NOT NULL,
 [Status] [nchar](10) NULL )
 
GO
 
--wrong table name:     [TEST].[NewTableName   


--code to fix the name issue with sp_rename

----*******************
--put the srong table name inside double quotes
sp_rename'TEST."[TEST].[NewTableName"','NewTableName'

----*******************


--or the way with escape like you did
sp_rename 'TEST.[[TEST]].[NewTableName]','NewTableName'

---The table name has been changed to  TableName with schema [TEST]
--Afyer rename
[TEST].[TableName] or ( TEST.TableName)

 

https://social.msdn.microsoft.com/Forums/en-US/d5f0caa9-2062-4df5-85c6-ac7f95524020/renaming-a-table?forum=transactsql

https://msdn.microsoft.com/en-us/library/ms188351%28v=sql.110%29.aspx?f=255&MSPPError=-2147217396

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