Connect to the server where in the DB you want to rename is located.
Modify the following script and run it
1
2
3
4
5
6
7
8
9
10
11
-- Replace all MyDBs with the name of the DB you want to change its name
USE[MyDB];-- Changing Physical names and paths
-- Replace all NewMyDB with the new name you want to set for the DB
-- Replace 'C:...NewMyDB.mdf' with full path of new DB file to be used
ALTERDATABASEMyDBMODIFYFILE(NAME=' MyDB ',FILENAME='C:...NewMyDB.mdf');-- Replace 'C:...NewMyDB_log.ldf' with full path of new DB log file to be used
ALTERDATABASEMyDBMODIFYFILE(NAME=' MyDB _log',FILENAME='C:...NewMyDB_log.ldf');-- Changing logical names
ALTERDATABASEMyDBMODIFYFILE(NAME=MyDB,NEWNAME=NewMyDB);ALTERDATABASEMyDBMODIFYFILE(NAME=MyDB_log,NEWNAME=NewMyDB_log);
Right click on the DB and select Tasks>Take Offline
Go to the location that MDF and LDF files are located and rename them exactly as you specified in first two alter commands. If you changed the folder path, then you need to move them there.
Go back to Microsoft SQL Server Management Studio and right click on the DB and select Tasks>Bring Online.