SQL Basics
Querying Data
Filtering Data
Joining Tables
SQL Functions
Modifying Data
Defining Data
Types of SQL Commands
SQL has many 12 main commands and around 900 different keywords. In this tutorial, you will understand the different types of SQL commands.
To make our lives easier, SQL commands are divided into different command groups depending on their purpose:
- DDL – Data Definition Language
- DQL – Data Query Language
- DML – Data Manipulation Language
- DCL – Data Control Language
- TCL – Transaction Control Language
You may find in other documentation that SELECT is considered a DML and not a DQL. I disagree with this since SELECT only reads the data and does not manipulate or change it.
Let us look at each of the command types in depth!
DDL - Data Definition Language
Data Definition Language (DDL) is, as the name suggests, an SQL command that allows you to define, create and manipulate the structure of your databases, e.g. creating or deleting tables, columns, views, or any other objects in your database.
The following commands considered to be the main DDL commands:
- CREATE – creates new objects in the database.
- DROP – drops objects from the database.
- ALTER – alters the structure of objects in the database to be edited.
DQL - Data Query Language
Data Query Language, (DQL), contains only one command called SELECT. It helps you to retrieve information from your database.
SELECT is the most important command and concentrated focus of SQL. It contains many options and clauses which makes it very effective.
In my tutorials, I will explain everything about SELECT, because if you work with SQL you will end up writing tones of SELECT statements. So don’t worry about it 😀
DML - Data Manipulation Language
Data Manipulation Language, (DML), contains SQL commands used to manipulate your data inside your database.
More specifically, the DML command gives you tools to make changes to the records in a table, such as adding new records, deleting records, and updating records.
The following commands considered to be the main DML commands:
- INSERT – inserts data into a table.
- DELETE – deletes data from a table.
- UPDATE – updates existing data in a table.
DCL - Data Control Language
Data Control Language, (DCL), contains SQL commands that allow you to control who can access your data in the database.
Two general DCL commands are as following:
- GRANT – gives users access to the database.
- REVOKE – withdraws user access.
TCL - Transaction Control Language
Transaction Control Language (TCL), allows you to control and manage database transactions to maintain the integrity of your data.
Here are the main TCL commands:
- COMMIT – save changes in the database.
- ROLLBACK – restore the database to the point of the last COMMIT or SAVEPOINT in case of any error.
- SAVEPOINT – create a point in a transaction to which you can later rollback.
Final Thoughts ...
In many projects where I have used SQL, the most common term among experts is DDL. We call a SQL script that changes the structure of the database a DDL script.
So if you are in a project where you have to write SQL and you get a DDL task, that means you have to create, edit or delete an object in the database. 😅