SQL Server Error when Renaming a table – SP_RENAME – Msg 15225

So if you need to rename a table sp_rename is what you would use. You would do something like the following:

exec sp_rename ‘oldname’, ‘newname’;

Here is a gotcha, it doesn’t take into account a table name that has a dot in the name. For example a table like dbo.[employee.info] will create this error:

Msg 15225, Level 11, State 1, Procedure sp_rename, Line 332

No item by the name of ‘dbo.[employee.info]’ could be found in the current database ‘database’, given that @itemtype was input as ‘(null)’.

The parsing mechanism in the stored procedure will parse it incorrectly.

The Workaround

Use the fully qualified domain name of the table (ie. databasename.schema.tablename). I found that this will work in these cases.