Object-Level Permissions and Ownership Chaining
This lesson explains principals, GRANT, DENY and REVOKE, the securable hierarchy and ownership chaining.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how GRANT, DENY and REVOKE interact.
- Describe schema-level and column-level permissions.
- Explain ownership chaining and how module signing handles dynamic SQL.
Principals and roles
Database users are mapped to logins, to Microsoft Entra identities or are contained users; database roles group users. Fixed roles such as db_datareader, db_datawriter, db_ddladmin and db_owner grant broad rights to every object, so least-privilege designs create custom roles, grant them exactly the permissions a job needs, and add users or Microsoft Entra groups as members. Azure SQL Database also has special roles in the master database, such as dbmanager and loginmanager.
Least privilege?
GRANT, DENY and REVOKE
GRANT gives a permission, DENY explicitly forbids it and overrides any grant, including grants through other roles, and REVOKE removes a previous GRANT or DENY. Permissions apply to a securable hierarchy: a permission on the database covers all schemas, and a permission on a schema covers all objects in it, including objects created later. Column-level permissions limit SELECT, UPDATE or REFERENCES to listed columns. The following examples show common grants.
CREATE ROLE SalesReader;
CREATE ROLE AppExecutor;
GRANT SELECT ON SCHEMA::Sales TO SalesReader; -- every current and future object
DENY SELECT ON Sales.Customer (CreditLimit) TO SalesReader; -- except one column
GRANT EXECUTE ON SCHEMA::Api TO AppExecutor; -- procedures are the only path to data
GRANT EXECUTE ON EXTERNAL MODEL::EmbeddingModel TO AppExecutor;
ALTER ROLE SalesReader ADD MEMBER [[email protected]]; -- a Microsoft Entra groupPermission statements
Ownership chaining and module signing
When a view, procedure or function accesses another object with the same owner, SQL Server skips the permission check on the second object (ownership chaining). This is why granting EXECUTE on a procedure, or SELECT on a view, is enough even when the user has no permissions on the underlying tables, and why procedures and views can enforce controlled access. The chain breaks when the owners differ or when dynamic SQL runs, because dynamic SQL is checked against the caller. EXECUTE AS OWNER or signing the procedure with a certificate whose user has the needed permissions solves that without granting the caller table access; module signing is preferred because it grants only the specific permissions the certificate user has.
When the chain breaks
Procedure-only access
An API must change orders only through stored procedures in the Api schema. One procedure builds a dynamic ORDER BY with sp_executesql and fails with a SELECT permission error on Sales.Orders, while the other procedures work. The API's user must not get table permissions. What should the developer do?
Sign the failing procedure with a certificate, create a user from the certificate and grant that user SELECT on Sales.Orders (or use EXECUTE AS with a dedicated low-privilege user). Dynamic SQL breaks ownership chaining, so the caller's permissions are checked; module signing adds only the certificate user's permission while the procedure runs. Granting SELECT on the table to the API user would bypass the procedure-only design.
A user is granted SELECT through one role and denied SELECT through another. Can the user select?
Show answer
No. DENY overrides GRANT.
Exam Tips
Remember for the exam
- Least privilege: custom roles with specific grants; avoid db_owner and broad fixed roles.
- DENY overrides GRANT; REVOKE removes either.
- Schema-level grants cover objects created later.
- Dynamic SQL breaks ownership chaining; use module signing or EXECUTE AS.