REVOKE
REVOKE is a command in SQL that is used to take back or withdraw privileges or permissions from a user or a group of users. It is typically used by database administrators to manage access to the database system and its objects. The revoked permissions can include abilities to execute specific actions such as SELECT, INSERT, UPDATE, DELETE, or any other SQL operation. The command only impacts future sessions, not current ones.
Example
Output
Explanation
In this example, the REVOKE
statement is used to remove the INSERT
privilege from the new_user
. The user was initially granted ALL PRIVILEGES
. After the REVOKE
statement, ‘new_user’ no longer has the right to perform INSERT
operations on any database on the MySQL server.
Example
Output
Explanation
The REVOKE command is used to take away permissions granted to users. In this particular example, the INSERT privilege on a table is revoked from a specified user. The output “REVOKE” confirms the successful execution of the command. It is essential to note that the SQL command must be run by a user with the appropriate privileges.
Example
Output
Explanation
In the example provided, initially a user testUser
is created and granted SELECT
permissions on the TestTable
in the TestDatabase
. Later, the SELECT
permission that was granted to testUser
on TestTable
was revoked. The output signifies that all these commands have been executed successfully.
Example
Output
Explanation
In the provided SQL commands, a new user ‘test_user’ is initially created with a password ‘test_user_password’. Then, the privilege to create a session is granted to ‘test_user’. However, in the final statement, the privilege to create a session is revoked from the same ‘test_user’. The output represents the successful execution of these commands.
Example
Output
This will return:
Then if we attempt another SELECT
statement after the REVOKE
command:
This will return an error:
Explanation
In the provided example, we first create a table Test
and insert data into it. We also create a role ReadAccess
.
We then grant SELECT
permission on the Test
table to the ReadAccess
role. This means users with that role are allowed to read data from the Test
table.
Finally, we revoke the SELECT
permission from the ReadAccess
role on the Test
table. This denies the ReadAccess
role the ability to read data from the Test
table.
Please note, SQLite3 natively does not support the GRANT
and REVOKE
SQL commands, but many SQLite-based databases (like PostgreSQL and others) do support these commands. For those databases this example holds true.