Skip to content

Latest commit

 

History

History
66 lines (49 loc) · 3.39 KB

File metadata and controls

66 lines (49 loc) · 3.39 KB
title PowerShell: Add a Database to a Failover Group
description Use an Azure PowerShell example script to create a database in Azure SQL Database, add it to a failover group, and test failover.
author rajeshsetlem
ms.author rsetlem
ms.reviewer wiassaf, mathoma
ms.date 06/10/2025
ms.service azure-sql-database
ms.subservice high-availability
ms.topic sample
ms.custom
sqldbrb=1
devx-track-azurepowershell
ms.devlang powershell

Use PowerShell to add a database to a failover group

[!INCLUDEappliesto-sqldb]

[!div class="op_single_selector"]

This PowerShell script example creates a single database in Azure SQL Database, creates a failover group, adds the database to it, and tests failover.

[!INCLUDE quickstarts-free-trial-note] [!INCLUDE updated-for-az] [!INCLUDE cloud-shell-try-it.md]

If you choose to install and use PowerShell locally, this tutorial requires Az PowerShell 1.4.0 or later. If you need to upgrade, see Install Azure PowerShell module. If you're running PowerShell locally, you also need to run Connect-AzAccount to create a connection with Azure.

Sample scripts

:::code language="powershell" source="~/../azure_powershell_scripts/azure-sql/database/failover-groups/add-single-db-to-failover-group-az-ps.ps1" id="FullScript":::

Clean up deployment

Use the following command to remove the resource group and all resources associated with it.

Remove-AzResourceGroup -ResourceGroupName $resourceGroupName

Script explanation

This script uses the following commands. Each command in the table links to command specific documentation.

Command Notes
New-AzResourceGroup Creates a resource group in which all resources are stored.
New-AzSqlServer Creates a server.
New-AzSqlServerFirewallRule Creates a server-level firewall rule for a server.
New-AzSqlDatabase Creates a new database.
New-AzSqlDatabaseFailoverGroup Creates a new failover group.
Get-AzSqlDatabase Gets one or more databases.
Add-AzSqlDatabaseToFailoverGroup Adds one or more databases to a failover group.
Get-AzSqlDatabaseFailoverGroup Gets or lists failover groups.
Switch-AzSqlDatabaseFailoverGroup Executes a failover of a failover group.
Remove-AzResourceGroup Removes a resource group

Related content