How to rename a SQL Server database?
This article describes, how to rename a SQL database name by T-SQL query.
There are some limitations to renaming a SQL database name. Please find below the limitations:
- System databases can't be renamed
- Databases cannot be renamed when anyone is using that database
- Renaming a database name does not mean that it will rename the physical file of the database like MDF, NDFand LDF file name.
ALTER permission is required to rename the SQL Database.
Find below the T-SQL query to rename a SQL database.
ALTER DATABASE OldDBName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE OldDBName MODIFY NAME = NewDBName;
ALTER DATABASE NewDBName SET MULTI_USER;