Table of contents
1.
Introduction
2.
What is Grant?
2.1.
Syntax
2.2.
Example
3.
What is Revoke?
3.1.
Syntax
3.2.
Example
4.
Difference between Grant and Revoke
5.
Frequently Asked Questions
5.1.
What is the difference between deny and REVOKE when it comes to permissions?
5.2.
What do you understand about DCL?
5.3.
What is the use of the Grant command?
5.4.
What is the use of the Revoke command?
6.
Conclusion 
Last Updated: Apr 24, 2024
Easy

Difference between Grant and Revoke

Introduction

Grant and Revoke are two different types of Data Control language commands that decide on the permissions and control the user's access to the database. Use the GRANT command to permit users and the REVOKE command to remove authorization.

Difference between Grant and Revoke

This blog will discuss the Grant and Revoke commands along with their syntax and examples. Further, we will list the difference between Grant and Revoke, thus understanding how each command affects system security and maintains data integrity.

You can also read about DCL command in DBMS and Tcl Commands in SQL

What is Grant?

The Grant command allows certain permissions and privileges to the database users. Access rights to different users can be defined using the GRANT command. Only authorized users can perform SELECT, INSERT, UPDATE, and DELETE operations on the specified data tables.

Syntax

The syntax of the Grant Command is:

GRANT privilige_name on object_name to {user_name | public | role_name} ;

Example

The example of Grant command is:

GRANT INSERT, SELECT ON Employees TO Ninja;

What is Revoke?

The revoke command is a type of DCL command that cancels the database permissions allowed to the users. In SQL language, it can be said that the revoke command REVOKES the access rights from the user, thereby limiting the operations that can be performed by the user on the database.

Read more about MySQL revoke privilege

Syntax

The syntax of the Revoke Command is:

REVOKE privilige_name on object_name from {user_name | public | role_name} ;

Example

The  example of the Revoke Command is:

REVOKE INSERT, SELECT ON Employees FROM Ninja;


Now, that we have understood each of the commands separately, let us list down the difference between grant and revoke.

Difference between Grant and Revoke

The difference between grant and revoke commands are:

Particular Grant Revoke
Action The grant command allows access permissions to the database user. The revoke command cancels the permissions allowed by the grant command from the database user. 
Operation Adds privileges to a user or object Removes privileges from a user or object
Effect Enables specified actions Disables specified actions
Use Case Initially granting permissions Removing previously granted permissions

Also see, pwd command in linux

Also know about Difference Between Compiler and Interpreter and Assembler here. 

Frequently Asked Questions

What is the difference between deny and REVOKE when it comes to permissions?

Deny permanently blocks access to a resource, while REVOKE removes previously granted access, restoring default permissions temporarily or permanently.

What do you understand about DCL?

Data Control Language or DCL is part of SQL that deals with the authorizations, access, permissions, and security features of managing the data in a relational database. The DCL commands control the access rights and maintain the data security and integrity of the database.

What is the use of the Grant command?

The Grant command allows specific permissions and privileges to the database users. Access rights to different users can be defined with the help of the GRANT command. It allows only validated users to perform SELECT, INSERT, UPDATE, and DELETE operations on the specified database objects.

What is the use of the Revoke command?

The revoke command is a type of DCL command that cancels or revokes the database permissions allowed to the users, thereby limiting the operations that can be performed by the user on the database.

Conclusion 

Kudos, Ninja, on making it to the finish line of this article! Grant and revoke are DCL commands that are useful in controlling the access and permissions of the user over the database. Through this blog we have covered all the difference between grant and revoke.

We hope this blog was helpful to you in understanding the key difference between Grant and Revoke. Keep learning! We recommend you read some of our other SQL articles: 

  1. Constraints in SQL
  2. SQL introduction
  3. Top 100 SQL problems
  4. Sql functions

 

Refer to our Guided Path to enhance your skills in DSACompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may practice the mock test series and participate in the contests hosted on Coding Ninjas Studio!

But suppose you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. You must look at the problemsinterview experiences, and interview bundles for placement preparations.

We are rooting for you! 

Happy Learning!

Live masterclass