I have a requirement, where I need to create a new data base in a azure SQL data base by opening a master connection. So for that I need to check if that user have the permission t create new data base or not. For tradition SQL, I am providing ‘dbcreator’ roll to user and
string query = "SELECT IS_SRVROLEMEMBER('dbcreator') IS_DBCREATOR";
using above query to check the if the user have permission to create new data base.
Now same thing I have to implement over azure SQL database. So what roll I have to assign to user/server so I will allow to create new data bases. And what query I need to use to check if user have creator permission.
2
Answers
According the CREATE DATABASE documentation:
For the
dbmanager
role membership, the user needs a server level login, a master database user, and membership of thedbmanager
database role.Example to grant an existing login permissions to create databases in
master
database context:To check the current user for
dbmanager
database role membership (in themaster
database context):To check if the current user has
CREATE DATABASE
permissions viadbmanager
role membership or other means (e.g. administrator):You can make use of dbmanager and loginmanager roles to grant permission to the user to create a new database. Connect to the master database with server admin and run the below command to add a role to the user:
Connect to the master database with the user and
create database <dbName>
to create the table. It will run successfully as shown below:The database will be created successfully as shown below:
For more information you can refer this.