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.

Advertisements

Have an opinion? Leave an opinion!

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