SQL Server Create Read Only User for One Database

Published
Length
3 min read

Luis Felipe Dias

All posts

To handle a sql server create read only user for one database task, map a login or contained user to that database and add it to the fixed data reader role. This setup lets the user read all user tables and views in that single database without write permissions. Teams often need this setup for human engineers, reporting tools, and AI agents. Limiting an account to one database stops lateral movement across the server instance. It also keeps automated tools from changing or deleting production

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To handle a sql server create read only user for one database task, map a login or contained user to that database and add it to the fixed data reader role. This setup lets the user read all user tables and views in that single database without write permissions.

Teams often need this setup for human engineers, reporting tools, and AI agents. Limiting an account to one database stops lateral movement across the server instance. It also keeps automated tools from changing or deleting production records by mistake.

How to sql server create read only user for one database in practice

SQL Server splits access into two layers: server logins and database users. A database user is the identity a login takes when it enters a database. Microsoft supports thirteen types of database users for different access needs.

When someone needs access to many databases, admins create a login in the master database. Then they create a matching database user inside the target database. Every role in the database, including the public role, holds basic connection rights.

If an account only needs one database, a contained database user works well. A contained user has a password stored inside that single database. It does not link to a server login in the master database. An admin must first turn on contained databases on the server and the target database.

Once the user exists in the target database, you assign read permissions. SQL Server provides a fixed database role for reading data. Members of this role can read all data from all user tables and views. Admins add the user to this role using the standard role alteration statement. Note that Azure Synapse uses a different stored procedure to add role members.

You cannot change the permissions built into fixed database roles. If you must block write actions with certainty, you can also add the deny data writer role. Members of that role cannot add, change, or delete data in any user table.

Read-Only Root Filesystem + User Provisioning (SCIM): architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Security and operational tradeoffs of native read-only roles

Native roles give a solid baseline for database security. They stop an engineer or AI agent from running destructive write commands. Unlike the database owner role, a read-only user cannot change settings or drop the database.

Still, static read-only users still leave big operational gaps during an active session. A member of the fixed data reader role can read every user table and view. That includes tables holding sensitive customer data.

When an engineer or AI tool queries a table, the database returns raw values. Emails, phone numbers, card numbers, and national IDs come back in plain text. Native fixed roles do not rewrite or mask these sensitive fields in query results. If you want to block a user from reading specific tables, you must manage separate table permissions or use the deny data reader role, which blocks all user tables and views.

Managing static passwords for contained users or server logins also adds daily toil. Teams have to share, rotate, and revoke credentials across people and scripts. If a password leaks, anyone holding it can pull full tables from that database. Native roles control which objects a user can read. However, they do not inspect individual queries or filter sensitive columns on the fly.

Add runtime guardrails beside SQL Server

Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev sits inline in the TDS protocol beside the database as a sidecar for your SQL Server. For every query an agent or human runs in production, hoop.dev decides whether to pass, mask, block, or escalate it for review.

With hoop.dev SQL Server controls, rules refuse banned statements before they run, hold risky queries for human review, and mask matched sensitive values in supported result columns in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.

Frequently asked questions

What is the difference between a SQL login and a contained database user?

A SQL login lives in the master database and can map to many databases on the server. A contained database user keeps its password inside one database and does not need a login in master, though an admin must enable containment first.

Can you change the permissions of the fixed data reader role in SQL Server?

No, SQL Server does not let you change the permissions assigned to fixed database roles. Members of the data reader role can always read all data from all user tables and views in that database.

How do you make sure a SQL Server user can never write data?

Do not add the user to the data writer or database owner roles. For an extra safeguard, you can add the user to the fixed deny data writer role, which blocks adding, changing, or deleting data in user tables.

The query runs. The emails stay hidden.