Help Center> Relational Database Service> User Guide> Working with RDS for SQL Server> Usage of Stored Procedures> Removing Custom Databases from Availability Groups (Only for Microsoft SQL Server 2017 Enterprise Edition)

Removing Custom Databases from Availability Groups (Only for Microsoft SQL Server 2017 Enterprise Edition)

Scenarios

You can use a stored procedure to remove a custom database from the availability group [AG-RDS-YUN].

The stored procedure supports Microsoft SQL Server 2017 Enterprise Edition only.

Prerequisites

  • An RDS Microsoft SQL Server DB instance has been connected. For details about how to connect to a DB instance, see Connecting to a DB Instance Through a Public Network.
  • The custom database to be removed must have been added to the [AG-RDS-YUN] availability group. If you remove a database that has not been added to the availability group, the system displays the following information:
    Database Database name is not joined to AG-RDS-YUN.

Constraints

You cannot remove system databases. If you attempt to remove a system database, the system displays the following information:
Error DBName can not  in ('msdb','master','model','tempdb','rdsadmin','resource') .

Procedure

To remove a custom database from an availability group, run the following command:

EXEC rdsadmin.dbo.rds_remove_database_from_ag '@DBName';

@DBName: specifies the custom database to be removed.

For example, to remove database testDB_1 from the availability group [AG-RDS-YUN], run the following command:

EXEC rdsadmin.dbo.rds_remove_database_from_ag 'testDB_1';