Home > SQL Server > Change Database Name in SQL Server

Change Database Name in SQL Server

December 23rd, 2008 Leave a comment Go to comments

SQL Server Enterprise Manager does not let you change your database name once you create it. If you want to change your database name, you may have to manually run the following script to change it. First of all you have to login to SQL Server using osql command line utility. Once you are in, fire following commands to rename database.

ALTER DATABASE OldName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
go

sp_renamedb 'OldName', 'NewName'
go

ALTER DATABASE NewName SET MULTI_USER
go
Categories: SQL Server Tags: , , ,
  1. Pablo Alonso
    November 16th, 2009 at 14:39 | #1

    Hi, what if I need to chance the database file name also?

    I can’t find how to duplicate a database…. if you can help me please write me at pablo.alonso@itsas.com.ar

    thank you very much

    regards,
    Pablo

  1. No trackbacks yet.