Loading
Types of SQL Commands-tutorial
SQL (Structured Query Language) is used to manage and interact with databases.
But all SQL commands are not the same they serve different purposes.
So, SQL commands are categorized into five main types, each handling a specific part of database operations.


What Are SQL Commands?

SQL commands are instructions you give to a database.
They tell the database what to do like creating a table, inserting data, or giving permission to users.


1. DDL – Data Definition Language

Purpose: Defines or changes the structure of the database (like tables, columns, etc.)

CommandDescriptionExample
CREATECreates a new database object (table, view, etc.)CREATE TABLE Students (ID INT, Name VARCHAR (50));
ALTERModifies an existing table structureALTER TABLE Stdents ADD Age INT;
DROPDeletes an existing database objectDROP TABLE Students;
TRUNCATERemoves all data from a table but keeps structureTRUNCATE TABLE Students;

DDL commands auto-save changes, so they cannot be rolled back easily.


2. DML – Data Manipulation Language

Purpose: Used to manipulate or manage data inside tables.


CommandDescriptionExample
INSERTAdds new recordsINSERT INTO Students VALUES (1, 'Amit', 22);
UPDATEModifies existing recordsUPDATE Students SET Age = 23 WHERE ID = 1;
DELETERemoves recordsDELETE FROM Students WHERE ID = 1;
SELECTRetrieves data from tablesSELECT * FROM Students;

DML commands can be rolled back if changes are not committed.


3. DCL – Data Control Language

Purpose: Controls access and permissions to the database.

CommandDescriptionExample
GRANTGives permission to usersGRANT SELECT ON Students TO user1;
REVOKETakes back permissionREVOKE SELECT ON Students FROM user1;

Used mostly by database administrators for security control.


4. TCL – Transaction Control Language

Purpose: Manages changes made by DML commands and controls transactions.


CommandDescriptionExample
COMMITSaves all change permanentlyCOMMIT;
ROLLBACKUndo uncommitted changesROLLBACK;
SAVEPOINTCreates a poin to rollback partiallySAVEPOINT save1;

TCL ensures data consistency and prevents data loss during transactions.


5. DQL – Data Query Language

Purpose: Retrieves data from the database.
It mainly includes the SELECT command.

SELECT Name, Age FROM Students WHERE Age > 20;

Note: Some databases consider SELECT under DML, but it is often treated as a separate DQL category.


Two Minute Drill

  • DDL - Structure Commands (CREATE, ALTER, DROP)
  • DML - Data commands (INSERT, UPDATE, DELETE, SELECT)
  • DCL - Security commands (GRANT, REVOKE)
  • TCL - Transaction commands (COMMIT, ROLLBACK, SAVEPOINT)
  • DQL - Query command (SELECT)