SQL - GRANT AND REVOKE

FatimaAlam1234 - Dec 4 '23 - - Dev Community

GRANT

The GRANT statement allows database administrators to grant permissions or privileges on a database object to users. There are various types of privileges like SELECT, INSERT, UPDATE, DELETE, REFERENCES, ALL.

GRANT privilege_name
ON object_name
TO {user_name |PUBLIC |role_name}
[WITH GRANT OPTION];
Enter fullscreen mode Exit fullscreen mode
GRANT SELECT ON employees TO user1;
Enter fullscreen mode Exit fullscreen mode

REVOKE

The REVOKE statement can be used when we want to revoke some or all of the privileges that were assigned earlier to a user or a group of users. The syntax for using the REVOKE command is similar to the GRANT command.

REVOKE privilege_name
ON object_name
FROM {user_name |PUBLIC |role_name}
Enter fullscreen mode Exit fullscreen mode

Example:

REVOKE SELECT ON employees FROM user1;
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .