SQL Server Grant Select on Table

Published
Length
3 min read

Luis Felipe Dias

All posts

You use a sql server grant select on table permission to give read access to one table. This rule lets a database user read rows without changing data or viewing other tables. Teams use this rule when a full read role gives too much access. You can assign this right to a single user or a custom role. This approach keeps data safe for people and AI agents. How sql server grant select on table works in practice Before you grant table rights, the person or bot needs a database user identity. A

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.

You use a sql server grant select on table permission to give read access to one table. This rule lets a database user read rows without changing data or viewing other tables.

Teams use this rule when a full read role gives too much access. You can assign this right to a single user or a custom role. This approach keeps data safe for people and AI agents.

How sql server grant select on table works in practice

Before you grant table rights, the person or bot needs a database user identity. A database user is the identity of a login when it connects to a database. Microsoft SQL Server supports thirteen types of database users.

When someone needs access to many databases on an instance, a standard user works well. This user links to a login in the master database. When a user only needs one or a few databases, you have another option. You can create a contained database user with its own password. This contained user does not tie to a login in the master database. First, an admin must turn on contained databases on the server and database.

Once the user exists, all roles, including the public role, have the connect right. From there, admins often look at fixed database roles. Members of the fixed data reader role can read all user tables and views. Still, you cannot change the permissions assigned to fixed database roles.

If a team member or AI agent only needs one table, the fixed role is too broad. Instead, an admin grants the select permission on that single table. You can grant it to the user or to a custom role. This step limits the user to reading only that specific table.

Security tradeoffs of static roles and credentials

Granting select on a single table is much safer than using broad fixed roles. For example, the fixed owner role can run all maintenance tasks and drop the database. The fixed data writer role can add, delete, or change data in all user tables. Even the fixed data reader role exposes every user table and view in the database. By contrast, a table grant keeps other tables hidden.

Single Sign-On (SSO) + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Admins can also use fixed deny roles to block access across a database. The fixed deny data reader role stops a user from reading any user tables or views. It also blocks metadata about those tables. The fixed deny data writer role stops a user from adding, changing, or deleting data. Still, table grants and deny roles have limits during an active session.

First, static database logins and passwords stay active until an admin rotates them. If a script or AI agent leaks a password, anyone with that key can log in. Second, a table select rule gives access to every row and column in that table. Customer tables often hold emails, phone numbers, card numbers, or national IDs.

Native table grants return all of those fields in plain text. You also have to manage custom roles across every database on every server. As your team grows, tracking who can read which table takes a lot of time. Adding query logs and field masking at the access layer solves these gaps. Dynamic masking rewrites matched fields like emails or card numbers in query results.

Govern SQL Server queries and responses in flight

Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev sits inline in the TDS wire protocol next to SQL Server as a sidecar for your SQL Server. On every production batch from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for approval.

With hoop.dev guardrails and hoop.dev data masking, banned statements are refused or held for review, matched sensitive fields in supported result columns are masked in memory, and each decision is logged. Check out the code on GitHub.

Frequently asked questions

When should I grant select on one table instead of using the data reader role?

Use a single table grant when a user or bot only needs specific data. The fixed data reader role lets members read all data from all user tables and views. You cannot change the permissions on fixed roles, so table grants are better for strict access.

Should I use a standard login user or a contained user for table access?

Use a standard user with a master login if the person needs many databases on an instance. Use a contained database user with a password for access to one or a few databases. Remember that an admin must first turn on contained databases on the server and database.

How do I block a user from reading data if they belong to broad roles?

You can add the user to the fixed deny data reader role. Members of this role cannot read any data or metadata from user tables and views. For single tables, you can also revoke or deny the select permission on that specific object.

The query runs. The emails stay hidden.