Data control language
A data control language is a syntax similar to a computer programming language used to control access to data stored in a database. In particular, it is a component of Structured Query Language. Data Control Language is one of the logical groups in SQL Commands. SQL is the standard language for relational database management systems. SQL statements are used to perform tasks such as insert data to a database, delete or update data in a database, or retrieve data from a database.
Though database systems use SQL, they also have their own additional proprietary extensions that are usually only used on their system. For example, Microsoft SQL server uses Transact-SQL, which is an extension of SQL. Similarly, Oracle uses PL-SQL, which an Oracle-specific SQL extension. However, the standard SQL commands such as "Select", "Insert", "Update", "Delete", "Create", and "Drop" can be used to accomplish almost everything that one needs to do with a database.
Examples of DCL commands include the SQL commands:
- GRANT to allow specified users to perform specified tasks.
- REVOKE to remove the user accessibility to database object.
Microsoft SQL Server
In Microsoft SQL Server there are four groups of SQL commands:- Data Manipulation Language
- Data Definition Language
- Data Control Language
- Transaction Control Language
DCL commands are:
;GRANT: gives specified permissions for the table to, or assigns a specified role with certain permissions to, specified groups or users of a database;
;REVOKE: takes away specified permissions for the table to, or takes away a specified role with certain permissions to, specified groups or users of a database;
;DENY: denies a specified permission to a security object.
For example: GRANT can be used to give privileges to user to do SELECT, INSERT, UPDATE and DELETE on a specific table or multiple tables.
The REVOKE command is used to take a privilege away or revoking specific command like UPDATE or DELETE based on requirements.
Example
In the first example, GRANT gives privileges to user User1 to do SELECT, INSERT, UPDATE and DELETE on the table named Employees.In the second example, REVOKE removes User1's privileges to use the INSERT command on the table Employees.
DENY is a specific command. We can conclude that every user has a list of privilege which is denied or granted so command DENY is there to explicitly ban you some privileges on the database objects.:
Oracle Database
divide SQL commands to different types. They are:- Data Definition Language Statements
- Data Manipulation Language Statements
- Transaction Control Statements
- Session Control Statements
- System Control Statement
- Embedded SQL Statements
Data definition language statements let you perform these tasks:
- Create, alter, and drop schema objects
- Grant and revoke privileges and roles
- Analyze information on a table, index, or cluster
- Establish auditing options
- Add comments to the data dictionary
Example
Transaction Control Statements in Oracle
Transaction control statements manage changes made by DML statements. The transaction control statements are:- COMMIT
- ROLLBACK
- SAVEPOINT
- SET TRANSACTION
- SET CONSTRAINT
MySQL
- Data Definition Statements
- Data Manipulation Statements
- Transactional and Locking Statements
- Replication Statements
- Prepared Statements
- Compound Statement Syntax
- Database Administration Statements
- Utility Statements
- Account Management Statements
The Grant and Revoke statements are part of Account Management Statements.
The GRANT statement enables system administrators to grant privileges and roles, which can be granted to user accounts and roles. These syntax restrictions apply:
- GRANT cannot mix granting both privileges and roles in the same statement. A given GRANT statement must grant either privileges or roles.
- The ON clause distinguishes whether the statement grants privileges or roles:
- With ON, the statement grants privileges.
- Without ON, the statement grants roles.
- It is permitted to assign both privileges and roles to an account, but you must use separate GRANT statements, each with syntax appropriate to what is to be granted.
Examples
In PostgreSQL, executing DCL is transactional, and can be rolled back.Grant and Revoke are the SQL statements are used to control the privileges given to the users in a Databases.
SQLite does not have any DCL commands as it does not have usernames or logins. Instead, SQLite depends on file-system permissions to define who can open and access a database.