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

CREATE DATABASE AS COPY does not work with Azure

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

Problem

I'm new with T-SQL and MSSQL but need to copy Azure SQL database from one server to another.

As I googled here - it can be done with a CREATE DATABASE Database1_copy AS COPY OF server1.Database1; query, but in my Vusial Studio Code editor on the Ubuntu Linux with the vscode-mssql extention - I have an error:


Msg 156, Level 15, State 1, Line 1 : Incorrect syntax near the keyword 'database'.

My full query looks next:

CREATE DATABASE Database1_copy AS COPY OF oldserver.database.windows.net.olddatabasenamehere;


Additional googling leads me to the same solutions (here is another example I found).

What I'm doing wrong here?

I understood that even the first link published on Azure's resource (azure.microsoft.com) - it does not necessarily is working solution for Azure's SQL.

P.S. Idea is to automate DEV environment rollout (with ARM templates) as a copy of the current Live environment, with creating databases as a copy of Live's databases.

Solution

From BOL :


The AS COPY OF argument does not support the fully qualified unique domain names. In other words, if your server's fully qualified domain name is serverName.database.windows.net, use only serverName during database copy.

So your command should be

CREATE DATABASE Database1_copy AS COPY OF oldserver.olddatabasenamehere;

Code Snippets

CREATE DATABASE Database1_copy AS COPY OF oldserver.olddatabasenamehere;

Context

StackExchange Database Administrators Q#148444, answer score: 10

Revisions (0)

No revisions yet.