Sql-server – How to Rename a Database on a SQL Server Amazon RDS Instance

amazon-rdssql server

Attempts via SQL Server Management Studio and Transact SQL to rename a database hosted on a SQL Server Amazon RDS instance result in the following error.

User does not have permission to alter database 'Morningstar', the
database does not exist, or the database is not in a state that allows
access checks.

Note that this is the Transact SQL statement that I tried.

ALTER DATABASE <OldName> Modify Name = <NewName>;

The best option that I have come up with so far is to restore a copy of the original database with the new name and then delete the original. See my StackOverflow post for details on how to do this.

There are at least the following disadvantages to this approach.

  1. The export and import operations for a bacpac can take a long time.
  2. Any applications or websites that perform writes to the database will need
    to be taken offline during the whole process.
  3. There are manual steps involved which can result in errors.
  4. The RDS instance will need to be large enough to host two copies of the database if you want to leave the original there as a rollback strategy until the new one is available.

Can anyone suggest an alternative approach that does not have these disadvantages?

Update: I am interested in renaming a SQL Server database that is hosted within an RDS Instance – not the RDS Instance.

Best Answer

RDS has recently added a stored procedure to accomplish this:

EXEC rdsadmin.dbo.rds_modify_db_name N'<OldName>', N'<NewName>'

Source: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.SQLServer.CommonDBATasks.RenamingDB.html