26 January 2021

How to create reader / read-only user in azure database.

Source code viewer
  1. -- Run this on master database.
  2. CREATE LOGIN reader WITH password='MY_STRONG_PASSWORD';
  3. -- Run this in your database.
  4. CREATE USER reader FOR login reader;
  5. ALTER USER reader WITH DEFAULT_SCHEMA = MY_SCHEMA;
  6. ALTER ROLE db_datareader ADD MEMBER reader;
  7. EXEC sp_addrolemember 'db_datareader', 'reader';
Programming Language: SQL