I would like to create an SQL Azure user and grant her read-only access on a handful of DBs, what script can I use to achieve this?
Navigate to https://portal.azure.com and sign in to your subscription. Browse to SQL servers, pick your SQL server, and under Settings, choose Firewall / Virtual Networks. Click OFF under Allow Access to Azure Services and click the Save button. That's it!
Expand Security - Logins, then Right Click on login and then click Properties. Go to User Mapping tab and select the database on which you want to give permission and at bottom select db_datareader as shown below. Click Ok and you're done.
A pure TSQL script is super messy, SQL Azure disables the USE
command, so you are stuck opening connections to each DB you need to give the user read access.
This is the gist of the pattern.
In Master DB:
CREATE LOGIN reader WITH password='YourPWD'; -- grant public master access CREATE USER readerUser FROM LOGIN reader;
In each target DB (requires a separate connection)
CREATE USER readerUser FROM LOGIN reader; EXEC sp_addrolemember 'db_datareader', 'readerUser';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With