×
>
<

Aptitude

SQL DCL Commands

DCL Commandss

DCL includes commands such as GRANT and REVOKE which mainly deal with the rights, permissions, and other controls of the database system.

  • GRANT
  • REVOKE

GRANT Command

This command gives users access privileges to the database.

We have already learned about how to create user in MySQL using MySQL | create user statement. But using the Create User Statement only creates a new user but does not grant any privileges to the user account.Therefore to grant privileges to a user account, the GRANT statement is used.

Syntax
  
GRANT privileges_names ON object TO user;
  

Parameters Used:

  • privileges_name: These are the access rights or privileges granted to the user.
  • object:It is the name of the database object to which permissions are being granted. In the case of granting privileges on a table, this would be the table name.
  • user:It is the name of the user to whom the privileges would be granted.

Privileges:

The privileges that can be granted to the users are listed below along with description:

PrivilageDescription
SELECTSelect statement on tables.
INSERTInsert statement on the table
DELETEDelete statemnet on the table
INDEXCreate an index on an existing table
CREATECreate table statement
ALTERAbility to performe ALTER TABLE to change the table definition
DROPDrop table statement
ALLGrant all permission exept GRANT OPTION
UPDATEUpdate statement on the table
GRANTAllows to grant the privilage

Let us now learn about different ways of granting privileges to the users:

  1. Granting SELECT Privilege to a User in a Table: To grant Select Privilege to a table named “users� where User Name is Amit, the following GRANT statement should be executed.
    ALTER TABLE table_name ADD(column_name datatype);