How to Rename a Database

Discussion in 'MySQL' started by shivakhanal, Jul 12, 2008.

  1. #1
    a) Using sp_rename

    » Make sure that no user is using the database.
    » Make the database in the single user mode. You can do this by using sp_dboption.

    sp_dboption 'Pubs', 'single user', true

    » sp_rename Pubs, Library, Database

    Note : For renaming the database, you can also use sp_renamedb.

    sp_renamedb Pubs, Library

    » Bring back the database in multiuser mode

    sp_dboption 'Library', 'single user', false

    b) Using Detach & Attach

    sp_detach_db @dbname = N'Pubs'
    sp_attach_db @dbname = N'Library',
    @filename1 = N'd:\programfiles\MSSQL7\data\Pubs_Data.MDF',
    @filename2 = N'd:\program files\MSSQL7\data\Pubs_log.ldf'
     
    shivakhanal, Jul 12, 2008 IP
  2. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes , it is a long time I have not use the sql command.

    when I read the post

    sp_dboption 'Pubs', 'single user', true
    » sp_rename Pubs, Library, Database

    I remember. Yes that is the right.
     
    justinlorder, Jul 12, 2008 IP
  3. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Now I prefer apache + php + linux backed by mysql. Mysql is powerful and the php cms are easy to find.
     
    justinlorder, Jul 12, 2008 IP