Wednesday, September 29, 2021

Azure SQL Database: How to Create a ReadOnly User

This is a quick post on how we can create a Read-Only User for an Azure SQL Database.

1. First, connect to the target Azure SQL Server as the admin user. 

2. Now run the following script on the master database.

--on master

CREATE LOGIN [readonlyuser] WITH PASSWORD = '<password>';

CREATE USER [readonlyuser] FROM LOGIN [readonlyuser]
on master
3. Now run the following script on the target database.
--on target database

CREATE USER [readonlyuser] FROM LOGIN [readonlyuser]

EXEC sp_addrolemember 'db_datareader', 'readonlyuser';

on target database
That's it.

Hope this helps.

Happy Coding.


No comments:

Post a Comment