Changing Custom Database Names
Scenarios
You can use a stored procedure to change a custom database name.
Prerequisites
- An RDS for SQL Server DB instance has been connected. .
- For primary/standby DB instances, you need to run the following command to remove database mirroring between them:
alter database [dbname] set partner off
- After the primary database name is changed, the system will automatically establish mirroring relationship.
If you do not remove database mirroring for primary/standby DB instances and attempt to change the primary database name, the system displays the following information:
Database database name is on mirroring_state.
Constraints
- System database names cannot be changed. If you attempt to change the name of a system database, the system displays the following information:Error DBName_Source or DBName_Target. Please can not include in ('msdb','master','model','tempdb','rdsadmin','resource') .
- The new database name must be unique. If the new database name already exists, the system displays the following information:Database database name already exists. Cannot rename database with the same name.
Procedure
Run the following command to change a custom database name:
exec msdb.dbo.rds_rename_database N'oldname',N'newname';
- oldname indicates the original database name.
- newname indicates the new database name.
For example, to change a database name from ABC to XYZ, run the following command:
exec msdb.dbo.rds_rename_database N'ABC',N'XYZ';
If the database name is changed, the system displays the following information:
The database name 'XYZ' has been set.
After the database name is changed, the system will automatically perform a full backup.
Parent topic: Usage of Stored Procedures
- Scenarios
- Prerequisites
- Constraints
- Procedure