Tuesday, March 3, 2020

Rename SQL Server Database in AWS RDS

In AWS RDS based SQL Server, you cannot rename a database from SQL Server management studio. You will get an error about permissions. You need to use rdsadmin command to accomplish that.



If you get error:

Msg 5030, Level 16, State 2, Line 1
The database could not be exclusively locked to perform the operation.

Then you need to set the database first to single user, rename it and then revert back to multi user. Use following steps to rename SQL Server database in AWS RDS:

use master
ALTER DATABASE OldDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE    
exec rdsadmin.dbo.rds_modify_db_name 'OldDB','NewDB'
ALTER DATABASE NewDB SET MULTI_USER

Hope that helps.


No comments: