SQL REVOKE syntax
REVOKE privilege_name [, privilege_name, ...]
ON object_name
FROM { user_name | role_name | PUBLIC }
[ CASCADE | RESTRICT ];
Let’s break down the various parts of the REVOKE syntax:
REVOKE
: This is the keyword that initiates the revoke operation.privilege_name
: Specifies the name of the privilege that you want to revoke. It can be a specific privilege such as SELECT, INSERT, UPDATE, DELETE, or a more general one like ALL. You can revoke multiple privileges by separating them with commas.ON object_name
: Specifies the name of the object on which the privilege was granted. The object can be a table, view, stored procedure, or any other database object.FROM { user_name | role_name | PUBLIC }
: Specifies the user, role, or the PUBLIC keyword from which the privilege is being revoked. If you want to revoke the privilege from multiple users or roles, you can separate their names with commas.CASCADE | RESTRICT
: (Optional) Specifies the behavior of the revoke operation when the user or role being revoked has granted the privilege to other users or roles. CASCADE revokes the privilege from the dependent users or roles as well, while RESTRICT prevents the revoke operation if there are dependencies.
Here’s an example usage of the REVOKE statement to revoke the SELECT privilege on a table called “employees” from a user named “john”:
REVOKE SELECT ON employees
FROM john;
This will remove the SELECT privilege from the user “john” on the “employees” table.
Remember to use caution when revoking privileges, as it can have a significant impact on the user’s access rights within the database.