Change table name

  • I have a table in an DB called admin (dbo.admin)

    I want to change the name to administration (dbo.administration)

    How to script this change?

    I found 'Rename', and tried:

    ALTER TABLE dbo.admin

    RENAME TO administrator

    But it does not look like MSSQL 2005 knows the word RENAME

    Best regards

    Edvard Korsbæk

  • edvard 19773 (3/3/2011)


    I have a table in an DB called admin (dbo.admin)

    I want to change the name to administration (dbo.administration)

    How to script this change?

    I found 'Rename', and tried:

    ALTER TABLE dbo.admin

    RENAME TO administrator

    But it does not look like MSSQL 2005 knows the word RENAME

    Best regards

    Edvard Korsbæk

    Try this:

    create table OldName(

    Col1 int

    )

    sp_rename 'OldName', 'NewName'

    -Ki

    -Ki

  • RENAME is the oracle command to do what you are asking.

    in sql server, a stopred procedure is used:

    EXEC sp_rename 'admin','administration'

    or

    EXEC sp_rename 'dbo.admin','administration'

    note the first parameter can accept just the tablename, or the schemaname.tablename in order to clearly identify which object, and the second parameter is just the tablename...

    if you do this:

    EXEC sp_rename 'dbo.admin','dbo.administration'

    yould end up with a wierd tablename you must selec twith SELECT * FROM dbo.[dbo.administration]

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Use the system stored procedure sp_rename...

    sp_rename 'old name', 'new name'

  • Testet - Works like a charm!

    Thanks

    Edvard Korsbæk

Viewing 5 posts - 1 through 4 (of 4 total)

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