SQL SERVER – Understand Grant, Deny, and Revoke Permissions
SQL Server implements a permissions framework centered on discrete permissions and inheritance. It employs a straightforward and detailed strategy to regulate access to secured entities such as objects or statements. Users or roles can be granted, denied, or revoked permissions, constituting the foundational elements of SQL Server's security management. Let's delve into the concepts of Grant, Deny, and Revoke Permissions to gain a deeper understanding.
GRANT
the GRANT statement is used to explicitly give specific permissions to users or roles on database objects. These permissions define what actions a user or role can perform on the specified object. Here's a detailed understanding of the GRANT statement:
GRANT permission_name [, permission_name...]
ON object_name
TO {user_name | role_name | "PUBLIC"}
[WITH GRANT OPTION];
Example:
GRANT SELECT, INSERT ON dbo.EmpMaster TO HRRole;
This statement grants the SELECT and INSERT permissions on the EmployeeMaster table in the dbo schema to the HRRole role. Members of the HRRole role will now be able to select data from and insert data into the EmployeeMaster table.
Here are some commonly used permissions that can be granted using the GRANT statement:
Additional Considerations:
DENY
the DENY statement is used to explicitly deny specific permissions on database objects to users or roles. Unlike REVOKE, which removes previously granted permissions, DENY explicitly prohibits users or roles from performing certain actions on the specified objects. Here's a detailed understanding of the DENY statement:
DENY permission_name [, permission_name...]
ON object_name
TO {user_name | role_name | "PUBLIC"}
[CASCADE];
Example:
DENY DELETE ON dbo.EmpMaster TO TemporaryEmployeeRole;
This statement denies the DELETE permission on the EmployeeMaster table in the dbo schema to the TemporaryEmployeeRole role. Members of the TemporaryEmployeeRole role will now be prohibited from deleting data from the EmployeeMaster table.
领英推荐
Common Use Cases:
Additional Considerations:
REVOKE
the REVOKE statement is used to remove previously granted permissions on database objects from users or roles. It allows administrators to revoke specific permissions that were previously granted using the GRANT statement. Here's a detailed understanding of the REVOKE statement:
REVOKE {permission_name [, permission_name...]}
ON object_name
FROM {user_name | role_name | "PUBLIC"}
[CASCADE];
Example:
REVOKE SELECT, INSERT ON dbo.EmpMaster FROM HRRole;
This statement revokes the SELECT and INSERT permissions on the EmployeeMaster table in the dbo schema from the HRRole role. Members of the HRRole role will no longer have the ability to select data from or insert data into the EmployeeMaster table.
Common Use Cases:
Additional Considerations:
Conclusion
GRANT, DENY, and REVOKE statements are crucial for managing access control and maintaining security within a SQL Server database. These statements provide administrators with the flexibility to grant or restrict access to database objects based on specific requirements and user roles.
For Role in Sql server : (1) Role | LinkedIn
SQL DBA
11 个月you omitted the bigger picture and dove right into the weeds - without server level permissions there are no database level permissions