table rename problem

  • Hi all,

    by mistake i have renamed a table named 'claims' to 'sp_columns'. but now i want to get the original name to back. but when i am trying to do that it is showing the below error..

    can u help me to get it back

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

    No item by the name of 'sp_columns' could be found in the current database 'AdventureWorksDW', given that @itemtype was input as '(null)'.

    thanks.

    chandu

  • Please specify the exact object names, old table name, new table name and the exact syntax that you are using.

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • old table name: claims

    new table name: sp_columns

    database: adventureworksdw

    command: sp_rename 'sp_columns', 'claims'

  • Basically:

    sp_RENAME '[OldTableName]' , '[NewTableName]'

    http://blog.sqlauthority.com/2008/08/26/sql-server-how-to-rename-a-column-name-or-table-name/

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • ya u r right,

    wt my question is..

    my table name is 'claims',it is in 'adventureworksdw' database..

    by mistake i have renamed that 'claims' to 'sp_columns'

    now the table name is 'sp_columns'

    so now i want to get my original table name back

    for that i used command like

    sp_RENAME 'sp_columns','claims'

    now i am getting error mesg like

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

    No item by the name of 'sp_columns' could be found in the current database 'AdventureWorksDW', given that @itemtype was input as '(null)'.

  • ya u r right,

    wt my question is..

    my table name is 'claims',it is in 'adventureworksdw' database..

    by mistake i have renamed that 'claims' to 'sp_columns'

    now the table name is 'sp_columns'

    so now i want to get my original table name back

    for that i used command like

    sp_RENAME 'sp_columns','claims'

    now i am getting error mesg like

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

    No item by the name of 'sp_columns' could be found in the current database 'AdventureWorksDW', given that @itemtype was input as '(null)'.

  • I could not find a work around but you can change it in SSMS.

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • The OP did say it was by mistake. Does it work if you prefix it with dbo.tablename? E.g.:

    sp_RENAME 'dbo.sp_columns','claims'

    The problem is likely to do with the fact that sp_ is a system reserved prefix (for legacy reasons) and will look in the master database first. I'll see if I can recreate in a test env - does the rename work in the Management Studio UI (Right Click, Rename)?

  • Tried it out, also can't find a work-around (can't rename in the UI either). The only option I can find is to script the table, recreate it as the correct name, migrate data over then drop the misnamed one

  • you used the system keword while renaming the table thus it is not possible to revert,script out the exisitng table,create new table and import data.

    Regards,
    Shivrudra W

  • Thanks to all...

  • U r right, but it is working...

    upto creating the table it is working but while to import data from sp_columns it is not working and showing error like

    Msg 208, Level 16, State 3, Line 1

    Invalid object name 'sp_columns'.

  • Ouch. This is looking tricky. You can't even refer to the object name in a select statement (even fully referenced). I've tried adding a synonym to it, which lets you create it, but gives an error at runtime, scripting the data from SSMS (through SMO) which also doesn't work.

    I'm not seeing many other options other than restore from a backup at the moment, although someone else might be able to come up with a cunning plan

  • can any body solve this issue....

  • prudhivi9 (9/9/2011)


    can any body solve this issue....

    Post removed.

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 15 posts - 1 through 15 (of 20 total)

You must be logged in to reply to this topic. Login to reply