HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Copy Azure SQL Database Between Azure Subscriptions

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
sqldatabaseazurebetweensubscriptionscopy

Problem

Getting straight to the point, is this even possible?

I have successfully copied an Azure SQL database within the same subscription. In doing so, I kept it simple by copying the database to the same server (within the subscription). I used the Powershell commands Add-AzureRmAccount and New-AzureRmSqlDatabaseCopy.

I have tried executing the Add-AzureRmAccount twice (once for each subscription) but this seems to replace the first subscription with the second in the context as the New-AzureRmSqlDatabaseCopy command reports that it cannot find the specified resource group (which exists in the source subscription).

All that said, if this is something that is possible, what are the steps / commands that I need to execute?

Solution

Another option is to use CREATE DATABASE, as per Richard Hauer's answer on Stackoverflow (which I executed from SQL Server Management Studio v17.5):

CREATE DATABASE db_copy AS COPY OF ozabzw7545.db_original;


Some important notes:

  • SQL admin account and password were the same on both servers.



  • Servers were in different subscriptions.



-
Servers were on the same Tenant, checked via Azure PowerShell console with:

(Get-AzureRmSubscription -SubscriptionName ).TenantId 
(Get-AzureRmSubscription -SubscriptionName ).TenantId


You can monitor the progress with:

SELECT state_desc, name 
FROM sys.databases


Reference Links:

  • https://learn.microsoft.com/en-us/sql/t-sql/statements/create-database-azure-sql-database?view=azure-sqldw-latest#creating-a-copy-of-a-database-on-another-server



  • https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-move-resources



  • https://learn.microsoft.com/en-us/azure/sql-database/sql-database-copy

Code Snippets

CREATE DATABASE db_copy AS COPY OF ozabzw7545.db_original;
(Get-AzureRmSubscription -SubscriptionName <your-source-subscription>).TenantId 
(Get-AzureRmSubscription -SubscriptionName <your-destination-subscription>).TenantId
SELECT state_desc, name 
FROM sys.databases

Context

StackExchange Database Administrators Q#198659, answer score: 3

Revisions (0)

No revisions yet.