DDL, DML and DCL statements in MySQL with examples

Introduction

SQL (Structured Query Language) is the language use to access the data in a database. By using SQL, we can retrieve data from the database, we can modify or delete exiting data, we can also create new data in the database. Not only the data, using SQL we can work on the database objects also by creating new objects, modifying or deleting existing database objects. We can write SQL statements and execute them to perform database operations. There are various types of SQL commands - DDL, DML, DCL, etc. Let us discuss them here.

DDL (Data Definition Language)

DDL commands are those which are used to work on the database objects. They do not deal with the data but the database objects like tables. DDL commands are used to create, alter, drop, rename tables or other objects in the database. Some examples are: CREATE TABLE, ALTER TABLE, DROP TABLE, RENAME TABLE etc.

DML (Data Manipulation Language)

These SQL commands are used to manipulate data in the database. Like inserting, modifying or deleting data. So, these commands are used on the data stored in the database or used to create new data in the database. Examples: INSERT, UPDATE, DELETE statements.

DQL (Data Query Language)

DQL statements are those that retrieve the data from the database. It can fetch the required data and display them on the screen. It is called DQL as these statements are used to query on the database tables. Example: SELECT statement.

DCL (Data Control Language)

DCL commands are those that deal with the access or permission to the data or database objects in the database. These are used to grant permission or revoke access to some tables. Examples are GRANT, REVOKE, etc.

TCL (Transaction Control Language)

There is one more category of SQL commands, called TCL. These are used for transactions. A transaction consists of one or more SQL statements. They work as groups. If all statements in the transaction are executed successfully then the transaction is complete. If any of the statements fails, then the whole transaction fails. Examples are COMMIT and ROLLBACK.

Conclusion

SQL is required in almost all application that interacts with the database. We have discussed different category of the SQL commands in this topic. It is always good to know the type of SQL commands whenever you use it during project development.