Restrict DELETE Permission on a Table in SQL
Denying DELETE Permission on a Table
Write a SQL query to deny DELETE permission on a table to a user.
Solution:
-- Deny DELETE permission on the Customers table to a user.
DENY DELETE ON Customers TO UserG;
Explanation:
- Purpose of the Query :
- The goal is to demonstrate how to explicitly deny DELETE permission on a table to a specific user.
- Key Components :
- DENY DELETE: Prevents the user from deleting data from the specified table.
- ON Customers: Specifies the table being restricted.
- TO UserG: Specifies the user losing the permission.
- Why Deny Permissions? :
- Explicitly denying permissions ensures that users cannot perform restricted actions.
- It complements GRANT and REVOKE for fine-grained access control.
- Real-World Application :
- In customer relationship management (CRM) systems, denying DELETE permissions prevents accidental data loss.
Additional Notes:
- DENY takes precedence over GRANT, so use it carefully.
- Regularly audit denied permissions to ensure they align with security policies.
- Important Considerations:
- Avoid overusing DENY, as it can complicate permission management.
For more Practice: Solve these Related Problems:
- Write a SQL query to deny DELETE permission on the "Orders" table to a user named "Intern".
- Write a SQL query to explicitly deny DELETE permission on the "Inventory" table to a role named "Guests".
- Write a SQL query to revoke DELETE permission on the "Transactions" table from all users except administrators.
- Write a SQL query to ensure that no user can delete records from the "AuditLogs" table.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: Creating a Login and Mapping It to a user.
Next SQL Exercise: Using Certificates for Database Authentication.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics