简体   繁体   中英

Renamed a table to sp_help and cannot rename it back

Somehow one of our tables was accidentally renamed to 'sp_help'.

We have tried to rename it back to the previous table name using sp_rename but we are getting the following error:

Msg 15225, Level 11, State 1, Procedure sp_rename, Line 332
No item by the name of 'MyDatabase.dbo.sp_help' could be found in the current database 'MyDatabase', given that @itemtype was input as '(null)'.

We have also tried to rename it directly in management studio with the same error. Is there any other way of renaming this table back to the previous name?

ALTER the metadata of the dbo.sp_help object and perform a SWITCH.

Here's a test case that should get you started:

CREATE TABLE dbo.t_Foo
(
    Bar         BIT
);
GO

EXECUTE dbo.sp_rename @objname = 'dbo.t_Foo', @newname = 'sp_help';
GO

CREATE TABLE dbo.t_Foo
(
    Bar         BIT
);
GO

ALTER TABLE [dbo].[sp_help]
SWITCH TO dbo.t_Foo;
GO

SELECT  *
FROM    dbo.t_Foo;
GO

DROP TABLE [dbo].[sp_help]
GO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM