SQL Server Create User and Grant Permissions Read Only

Published
Length
3 min read

Luis Felipe Dias

All posts

To complete a sql server create user and grant permissions read only setup, you first make a database user. Then you add that user to the fixed data reader role so they can only read tables and views. Database admins do this task often for developers, analysts, and AI agents. Giving out full admin keys puts production data at high risk. A read-only setup stops people and scripts from changing or dropping tables by mistake. Still, you must know how logins, users, and roles fit together. How sq

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 complete a sql server create user and grant permissions read only setup, you first make a database user. Then you add that user to the fixed data reader role so they can only read tables and views.

Database admins do this task often for developers, analysts, and AI agents. Giving out full admin keys puts production data at high risk. A read-only setup stops people and scripts from changing or dropping tables by mistake. Still, you must know how logins, users, and roles fit together.

How sql server create user and grant permissions read only works in practice

In SQL Server, a login and a database user are two distinct things. A database user is the identity of a login inside one specific database. The platform supports thirteen distinct types of database users for various access needs.

You have two main paths when you set up a new database user. If a person needs to reach many databases on one server, use a standard login. You create the login in the master database first. Then you map a database user to that login inside each target database.

If someone needs to reach only one or a few databases, you have another option. You can make a contained database user with its own password. This user is not tied to a login in the master database. Before you do this, an admin must turn on contained databases on the server and the database.

Once the user exists, you must give it read rights. All database roles, including the public role, have basic connect rights by default. To grant read access, you add the user as a member of the fixed data reader role. In Azure Synapse, admins use an older role member procedure to add the user instead. Members of this data reader role can read all data from all user tables and views. You cannot change the permissions assigned to fixed database roles.

Sometimes you also want to block write actions for sure. The fixed data writer role lets members add, delete, or change data in all user tables. By contrast, the fixed deny data writer role stops a user from adding, changing, or deleting data. Adding a user to the data reader role and the deny data writer role locks in read-only status.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Security tradeoffs of static read-only roles and logins

Using a fixed read-only role is much safer than granting the database owner role. The database owner role can run all maintenance tasks and can even drop the whole database. Yet static read-only roles still leave big security gaps during an active session.

First, the fixed data reader role grants read access to every user table and view. You cannot edit this fixed role to hide one secret table. If a user or AI agent gets this role, they can read every row in the database by default. That includes raw emails, phone numbers, card numbers, and national IDs stored in user tables. Only the deny data reader role blocks reading all user tables and views, which is too broad.

Second, static logins and passwords create long-term key management work for your team. People share passwords in chat apps or save them in local text files. When an engineer leaves the team, admins must find and rotate those shared passwords.

Third, database roles do not inspect queries or mask sensitive fields on the fly. A read-only user can still pull millions of customer emails or card numbers in one query. To protect production data, teams need query logs and dynamic data masking that rewrites matched fields in results.

Check SQL Server batches and results on the wire

SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server, inline in the TDS wire protocol. On every batch an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

Before a batch hits the server, hoop.dev guardrails refuse disallowed actions with a native TDS error or hold risky statements for approval. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns in memory, and every decision is logged. Explore the MIT-licensed project on GitHub.

Frequently asked questions

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

A login lives in the master database and lets you enter the server instance. A database user is the identity of that login inside one specific database. You can also use a contained database user with a password, which does not need a master login.

Does the fixed data reader role allow users to change any table data?

No, members of the fixed data reader role can only read data from user tables and views. They cannot add, change, or delete rows unless they also belong to a role with write rights. To be extra safe, admins can also add the user to the fixed deny data writer role.

Can I edit the fixed data reader role to hide one specific table?

No, you cannot change the permissions assigned to any fixed database role in SQL Server. The fixed data reader role always grants read access to all user tables and views in that database. If you want to hide specific fields like card numbers, you must use custom permissions or data masking.

The query runs. The emails stay hidden.