Changing Database name

  • How do I change the name of an existing database?

    SQL Server 2000

  • exec sp_renamedb 'oldname', 'newname'

  • Thank you,

    Do i have to do anything with the .mdf, .ndf or .ldf?

  • not required

    -------------------------------------------------
    -Amit
    Give a man a fish and he'll ask for a lemon. Teach a man to fish and he wont get paged on weekends !! :w00t: - desparately trying to fish [/size]

  • No, if you want to change 'em along with the database name you need to run a separate command.

     

    Check out "ALTER DATABASE" in the books online.

    modify filename section.

  • I put a script in the library here about two weeks ago that was named "Switch_Database.sql", and it does it all... It was designed to allow a snapshot to be generated and completely ready to be used before the name change.  It changes the DB name, the logical name(s), and the physical file name(s)... and takes less than 20 seconds to do it all... it puts the DB into single user mode - so kicks off connections that will have to be reconnected; but that should be understandable.  There are comments in the file.  You might take a look.  It gets awfully confusing if you don't change everything together... and if you end up changing it more than once, or many times, it gets even harder when the logical and physical names aren't changed each time.

    Thank-you,
    David Russell
    Any Cloud, Any Database, Oracle since 1982

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

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