Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What permissions are needed to copy databases in SQL Azure

I wrote a little app to backup SQL Azure databases using the very usefull 'CREATE AS COPY OF' command in SQL Azure. e.g.

CREATE DATABASE MyNewDB AS COPY OF MyOldDB

I run this command with the admin login (first login you get when creating a server). My Question: What are the minimal permissions a new login would need to execute the above command?

So far here's what I've done:

-- IN MASTER DB --
CREATE LOGIN DBCreator WITH PASSWORD = '?????????????'
CREATE USER DBCreator FROM LOGIN DBCreator;
EXEC sp_addrolemember 'dbmanager', 'DBCreator';

-- IN MyOldDB --
-- (I ran this stuff when the previous commands didn't do it) --
CREATE USER DBCreator FROM LOGIN DBCreator;
EXEC sp_addrolemember 'db_datareader', 'DBCreator';  -- 

And the result when running the above CREATE DATABASE command:

CREATE DATABASE permission denied in database 'MyOldDB'.
like image 933
Joe Abrams Avatar asked Sep 12 '12 01:09

Joe Abrams


People also ask

What are the available permissions for Azure SQL Database account?

Azure SQL Database currently provides 7 fixed server roles. The permissions that are granted to the fixed server roles can't be changed and these roles can't have other fixed roles as members. You can add server-level logins as members to server-level roles.

Can you copy a SQL database?

On either the source or destination SQL Server instance, launch the Copy Database Wizard in SQL Server Management Studio from Object Explorer and expand Databases. Then right-click a database, point to Tasks, and then select Copy Database.


1 Answers

I could not add the db_owner role to new login, the command

EXEC sp_addrolemember 'db_owner', 'NewLogin'

throws the error

Cannot alter the role 'db_owner', because it does not exist or you do not have permission.

But using the dbmanager role works

EXEC sp_addrolemember 'dbmanager', 'NewLogin'

There is useful information in the article Managing Databases and Logins in Windows Azure SQL Database.

like image 102
dumbledad Avatar answered Oct 19 '22 10:10

dumbledad