Copy a Azure SQL database across subscriptions

Copy a Azure SQL database across subscriptions

If you want to copy an Azure SQL database across subscriptions there is no native way of doing this out-of-the-box in Azure.

You could do a backup and restore, but that is time-consuming and tedious work. Microsoft has pointed out in this article it can "only" be done by using T-SQL. Instead of manually going through this process every time, I decided to create a PowerShell script that encapsulates the SQL commands necessary to do the copy across subscriptions.

Requirements

Before we can proceed, please read the requirements:

Usage

You can use the following format for the script.

When you are using either SQL user or AAD Password as a authentication provider, you must provide username and password (must be secure string) for SQL server login.

The code

In the following code which also can be found on GitHub, you only need to adjust from line 31 to 61 according to your environment.

If you want to learn more about Azure SQL Database automation, then get in touch for an informal talk about your options.

Leave a comment