Changing MSSQL Database Name

SQL server

Trying to change from SSMS yields an error of database being locked for exclusive use.

Run these commands to set single user mode, change the DB name and then set back to multi user mode.

USE MASTER ALTER DATABASE MyDBPrev SET SINGLE_USER WITH ROLLBACK
IMMEDIATE ALTER DATABASE 
MyDBPrev MODIFY NAME = [MyDbNew]
ALTER DATABASE MyDbNew SET MULTI_USER

Post a Comment

Previous Post Next Post