Renaming Database

Sometimes you need to rename a SQL Server database. Beside the database name itself, this name is usually a part of logical database file names, physical file names, maybe file groups.
To rename the database name you need:

  1. Bring database offline;
  2. Change paths to database files in system catalog;
  3. Rename physical file names using Windows Explorer;
  4. Bring database online;
  5. Change database name;
  6. Change logical file names (optionally).

Here is the script to do this. Be careful to put the correct logical database file names.