SQL Server Authorization and Permissions

Last Updated: October 26, 2023

Authorization in SQL Server involves controlling access to securable objects (like tables, views, stored procedures) based on the permissions granted to users and roles. This mechanism ensures that only authorized individuals can perform specific actions on your database.

Understanding Permissions

Permissions define what actions a user or role can perform on a particular object. These can be granted, denied, or revoked. Key concepts include:

Types of Permissions

Permissions are categorized into several types:

Granting and Revoking Permissions

Permissions are managed using Transact-SQL (T-SQL) commands. The primary commands are:

Granting SELECT Permission on a Table

To grant the SELECT permission on a table named Customers to a user named AppUser, you would use the following T-SQL statement:

GRANT SELECT ON dbo.Customers TO AppUser;

Revoking INSERT Permission on a Table

To revoke the INSERT permission on the same table from AppUser:

REVOKE INSERT ON dbo.Customers FROM AppUser;

Denying DELETE Permission on a Table

To explicitly prevent AppUser from deleting rows:

DENY DELETE ON dbo.Customers TO AppUser;

Important: DENY overrides GRANT. If a user is a member of a role that has been granted a permission, but the user has been explicitly denied that permission, the denial takes precedence.

Permissions Hierarchy

Permissions are hierarchical. For example, permissions granted at the server level might cascade down to databases, or permissions granted at the database level might apply to schemas and then to objects within the schema.

Managing Permissions with SQL Server Management Studio (SSMS)

SSMS provides a graphical interface for managing permissions, which can be more intuitive for many tasks:

  1. Connect to your SQL Server instance using SSMS.
  2. Navigate to the database, schema, or object you want to manage.
  3. Right-click on the object and select Properties.
  4. Go to the Permissions page.
  5. Here you can add users or roles and assign specific permissions.

Tip: Use fixed database roles (e.g., db_datareader, db_datawriter) and fixed server roles for common permission sets to simplify management.

Commonly Used Permissions

Best Practices

Caution: Incorrectly configured permissions can lead to security vulnerabilities or prevent legitimate users from performing their tasks.

Further Reading