From 23257b6ffb625fe2149f397d0457ce7ef22f9d09 Mon Sep 17 00:00:00 2001 From: ronazi <42060837+ronazi@users.noreply.github.com> Date: Fri, 28 Aug 2020 19:07:01 +0530 Subject: [PATCH] Provided the full script for copy between subscriptions Customers open a lot of support requests for copy between subscriptions. The finding the SID part might not be something they are familiar with. I have at least handled 10 customers with the same ask and I have always provided this script. It is better to have it in the doc itself to avoid support requests. --- articles/azure-sql/database/database-copy.md | 40 ++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/articles/azure-sql/database/database-copy.md b/articles/azure-sql/database/database-copy.md index f438aa027516f..a88e349d485c1 100644 --- a/articles/azure-sql/database/database-copy.md +++ b/articles/azure-sql/database/database-copy.md @@ -108,6 +108,46 @@ CREATE DATABASE Database2 AS COPY OF server1.Database1; You can use the steps in the [Copy a SQL Database to a different server](#copy-to-a-different-server) section to copy your database to a server in a different subscription using T-SQL. Make sure you use a login that has the same name and password as the database owner of the source database. Additionally, the login must be a member of the `dbmanager` role or a server administrator, on both source and target servers. +```sql +Step# 1 +Create login and user in the master database of the source server. + +CREATE LOGIN loginname WITH PASSWORD = 'xxxxxxxxx' +GO +CREATE USER [loginname] FOR LOGIN [loginname] WITH DEFAULT_SCHEMA=[dbo] +GO + +Step# 2 +Create the user in the source database and grant dbowner permission to the database. + +CREATE USER [loginname] FOR LOGIN [loginname] WITH DEFAULT_SCHEMA=[dbo] +GO +exec sp_addrolemember 'db_owner','loginname' +GO + +Step# 3 +Capture the SID of the user “loginname” from master database + +SELECT [sid] FROM sysusers WHERE [name] = 'loginname' + +Step# 4 +Connect to Destination server. +Create login and user in the master database, same as of the source server. + +CREATE LOGIN loginname WITH PASSWORD = 'xxxxxxxxx', SID = [SID of loginname login on source server] +GO +CREATE USER [loginname] FOR LOGIN [loginname] WITH DEFAULT_SCHEMA=[dbo] +GO +exec sp_addrolemember 'dbmanager','loginname' +GO + +Step# 5 +Execute the copy of database script from the destination server using the credentials created + +CREATE DATABASE new_database_name +AS COPY OF source_server_name.source_database_name +``` + > [!NOTE] > The [Azure portal](https://portal.azure.com), PowerShell, and the Azure CLI do not support database copy to a different subscription.