Remove-SqlAvailabilityDatabase

Removes the availability database specified by the InputObject or Path parameter from its availability group.
Remove-SqlAvailabilityDatabase [-Path*] <string> [-Script] [-Confirm] [-WhatIf] [<CommonParameters>]
Remove-SqlAvailabilityDatabase [-InputObject*] <AvailabilityDatabase> [-Script] [-Confirm] [-WhatIf][<CommonParameters>]

The Remove-SqlAvailabilityDatabase cmdlet removes the availability database specified by the InputObject or Path parameter from its availability group. If executed at the server instance that hosts the primary replica, this cmdlet removes the primary database and all corresponding secondary databases from the availability group. If executed at a server instance that hosts a secondary replica, this cmdlet removes only the local secondary database from the availability group; this secondary database is no longer joined to the availability group, but other copies of the database continue to be joined.

Parameters
-InputObject <AvailabilityDatabase>

  • This value is required
  • Accepts pipeline input ByValue

The AvailabilityDatabase object of the availability database to remove.

-Path <string>

  • This value is required

The path of the availability database. This is a mandatory parameter.

-Script [<SwitchParameter>]

Outputs a Transact-SQL script that performs the task executed by this cmdlet.

-Confirm [<SwitchParameter>]

Prompts you for confirmation before executing the command.

-WhatIf [<SwitchParameter>]

Describes what would happen if you executed the command without actually executing the command.

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs

Microsoft.SqlServer.Management.Smo.AvailabilityDatabase

Specifies the availability database to be removed.

Examples
  1. This command removes the availability database ‘MyDatabase’ from the availability group named ‘MyAg’:
    C:PS> Remove-SqlAvailabilityDatabase -Path SQLSERVER:SqlPrimaryComputerInstanceNameAvailabilityGroupsMyAgAvailabilityDatabasesMyDatabase
    

    Because the command is executed on the server instance that hosts the primary replica, the primary database and all its corresponding secondary databases are removed from the availability group. Data synchronization will no longer occur for this database on any secondary replica.

  2. This command removes all availability databases from the availability group named ‘MyAg’:
    C:PS> Get-ChildItem SQLSERVER:SqlPrimaryComputerInstanceNameAvailabilityGroupsMyAgAvailabilityDatabases | Remove-SqlAvailabilityDatabase
    
  3. This command removes the secondary database ‘MyDatabase’ from the secondary replica hosted by the server instance named ‘SecondaryComputerInstance’:
    C:PS> Remove-SqlAvailabilityDatabase -Path SQLSERVER:SqlSecondaryComputerInstanceNameAvailabilityGroupsMyAgAvailabilityDatabasesMyDatabase
    

    Data synchronization to the removed secondary databases ceases. This command does not affect the primary database or any other secondary databases. Note: To restart data synchronization on this secondary database, rejoin it to the availability group by using the Add-SqlAvailabilityDatabase cmdlet on the same server instance.

  4. This command outputs the Transact-SQL command that removes the availability database ‘MyDatabase’ from the availability group ‘MyAg’:
    C:PS> Remove-SqlAvailabilityDatabase -Path SQLSERVER:SqlPrimaryComputerInstanceNameAvailabilityGroupsMyAgAvailabilityDatabasesMyDatabase -Script
    

    The availability database is not actually removed by this command.

Additional Notes
 
Related Links