SQL > Data Definition Language (DDL) > Grant

In most instances, many users access the same database environment. It is often not a good idea to allow everyone full freedom to perform any operation on all the database objects. For example, if I have an important table, I would not want anyone to be able to drop the table or alter the content of the table. Most relational databases provide the ability for database administrators and users to manage such privileges. There are two main commands that allows this:

  • Grant: Gives user privileges.
  • Revoke: Removes user privileges.
SQL GRANT assigns specific database privileges—such as SELECT, INSERT, UPDATE, or DELETE—to users on database objects like tables and views. Use the optional WITH GRANT OPTION to allow a user to further delegate those privileges to others.

We will focus on GRANT here. REVOKE is covered in the next section.

It is worth noting that some lightweight databases, such as SQLite, do not implement GRANT and REVOKE commands. This is because such databases are intended to be an embedded database engine and hence user-level privileges are meaningless.

Syntax

The syntax for GRANT is as follows:

GRANT "Privilege_Name" ON "Database_Object" TO "User" [WITH GRANT OPTION];

The available "Privilege_Name" will vary depending on the relational database. Typical privileges include the following:

  • SELECT
  • INSERT
  • DELETE
  • UPDATE

In many databases there is a privilege called "ALL." However, granting the "ALL" privilege doesn't necessarily provide all the available privileges to a user. Exactly which privileges are included as part of "ALL" is database-dependent.

In some databases such as DB2, it is necessary to add the word USER before the user name. This is because in DB2 it is possible to grant privileges at three different levels (user, role, group), so it is necessary to be explicit on which level the grant would take effect to avoid any ambiguity.

It is also possible to grant privileges to all users. On many databases granting a privilege to PUBLIC means you are granting to all users. There are exceptions. For example, on MySQL you would use ''@'localhost'.

The links below show the types of privileges available for each of the databases:

The optional "[With Grant Option]" means "User" can grant the same "Privilege_Name" to other users.

Examples

Example 1: Grant one privilege to a user

To grant SELECT privilege on the "Sales" table to user tanner1, we type in the following:

GRANT SELECT ON Sales TO tanner1;

Example 2: Use WITH GRANT OPTION

To enable user tanner1 to have the SELECT privilege on the "Sales" table and be able to grant the SELECT privilege on this table to other users, we will type the following:

GRANT SELECT ON Sales TO tanner1 With Grant Option;

Please note that a user can only grant a privilege to others if that user has access to that privilege. For example, if user tanner1 only has SELECT privilege on a table, tanner1 cannot grant a different type of privilege (such as DELETE) on this table to other users.

Example 3: Grant one privilege to all users

To grant SELECT privilege on the "Sales" table to all users, we type in the following:

GRANT SELECT ON Sales TO public;

Frequently Asked Questions

Q: What does the SQL GRANT statement do?
A: SQL GRANT gives a user specific privileges on a database object such as a table or view. Common privileges include SELECT, INSERT, UPDATE, and DELETE.

Q: What is the WITH GRANT OPTION clause?
A: WITH GRANT OPTION allows the recipient user to further grant the same privilege to other users. A user can only delegate privileges they themselves possess.

Q: How do you grant privileges to all users?
A: In most databases, grant to PUBLIC to give all users access. For example: GRANT SELECT ON Sales TO public; In MySQL, use ''@'localhost' instead.

Q: Which databases support GRANT and REVOKE?
A: Most enterprise relational databases—Oracle, SQL Server, MySQL, PostgreSQL, and DB2—support GRANT and REVOKE. Lightweight embedded databases like SQLite do not, as user-level privileges are not applicable.

Next: SQL Revoke

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact