Australia/Sydney
BlogMarch 3, 2020

Rename SQL Server Database in AWS RDS

Fahd Mirza
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.


Share this post:
On this page

Let's Partner

If you are looking to build, deploy or scale AI solutions — whether you're just starting or facing production-scale challenges — let's chat.

Subscribe to Fahd's Newsletter

Weekly updates on AI, cloud engineering, and tech innovations