Skip to content

Commit

Permalink
Merge pull request MicrosoftDocs#61694 from ronazi/patch-1
Browse files Browse the repository at this point in the history
Provided the full script for copy between subscriptions
  • Loading branch information
ktoliver authored Jan 8, 2021
2 parents fc9f79e + 23257b6 commit 722e09a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions articles/azure-sql/database/database-copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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.
Expand Down

0 comments on commit 722e09a

Please sign in to comment.