Courses @35% Off Databases SQL MySQL PostgreSQL PL/SQL MongoDB SQL Cheat Sheet SQ
SQL Commands | DDL, DQL, DML, DCL and TCL
Commands
Last Updated : 26 Nov, 2024
SQL commands are essential for managing databases effectively. These
commands are divided into categories such as Data Definition Language
(DDL), Data Manipulation Language (DML), Data Control Language (DCL),
Data Query Language (DQL), and Transaction Control Language (TCL).
In this article, we will explain the different types of SQL commands,
including DDL, DML, DCL, DQL, and TCL. These SQL sublanguages serve
specific purposes and are important for effective database management.
What are SQL Commands?
SQL Commands are like instructions to a table. It is used to interact with
the database with some operations. It is also used to perform specific
tasks, functions, and queries of data. SQL can perform various tasks like
creating a table, adding data to tables, dropping the table, modifying the
table, set permission for users.
SQL Commands are mainly categorized into five categories:
DDL – Data Definition Language
DQL – Data Query Language
DML – Data Manipulation Language
DCL – Data Control Language
TCL – Transaction Control Language
Open In App
1. Data Definition Language (DDL) in SQL
DDL or Data Definition Language actually consists of the SQL commands
that can be used to defining, altering, and deleting database structures
such as tables, indexes, and schemas. It simply deals with descriptions of
the database schema and is used to create and modify the structure of
database objects in the database
Common DDL Commands
Command Description Syntax
Create database or its
CREATE TABLE table_name
objects (table, index,
CREATE (column1 data_type,
function, views, store
column2 data_type, ...);
procedure, and triggers)
Delete objects from the
DROP DROP TABLE table_name;
database
Open In App
Command Description Syntax
ALTER TABLE table_name
Alter the structure of the
ALTER ADD COLUMN column_name
database
data_type;
Remove all records from a
table, including all spaces TRUNCATE TABLE
TRUNCATE
allocated for the records are table_name;
removed
Add comments to the data COMMENT 'comment_text' ON
COMMENT
dictionary TABLE table_name;
RENAME TABLE
Rename an object existing
RENAME old_table_name TO
in the database
new_table_name;
Example of DDL
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
hire_date DATE
);
In this example, a new table called employees is created with columns for
employee ID, first name, last name, and hire date.
2. Data Query Language (DQL) in SQL
DQL statements are used for performing queries on the data within
schema objects. The purpose of the DQL Command is to get some
schema relation based on the query passed to it. This command allows
getting the data out of the database
Open to perform operations with it. When a
In App
SELECT is fired against a table or tables the result is compiled into a
further temporary table, which is displayed or perhaps received by the
program.
DQL Command
Command Description Syntax
SELECT column1, column2,
It is used to retrieve data
SELECT ...FROM table_name WHERE
from the database
condition;
Example of DQL
SELECT first_name, last_name, hire_date
FROM employees
WHERE department = 'Sales'
ORDER BY hire_date DESC;
This query retrieves employees’ first and last names, along with their hire
dates, from the employees table, specifically for those in the ‘Sales’
department, sorted by hire date.
3. Data Manipulation Language (DML) in SQL
The SQL commands that deal with the manipulation of data present in
the database belong to DML or Data Manipulation Language and this
includes most of the SQL statements. It is the component of the SQL
statement that controls access to data and to the database. Basically, DCL
statements are grouped with DML statements.
Common DML Commands
Open In App
Command Description Syntax
INSERT INTO table_name (column1,
Insert data into a
INSERT column2, ...) VALUES (value1,
table
value2, ...);
Update existing UPDATE table_name SET column1 =
UPDATE data within a value1, column2 = value2 WHERE
table condition;
Delete records
DELETE FROM table_name WHERE
DELETE from a database
condition;
table
Table control
LOCK LOCK TABLE table_name IN lock_mode;
concurrency
Call a PL/SQL or
CALL CALL procedure_name(arguments);
JAVA subprogram
Describe the
EXPLAIN EXPLAIN PLAN FOR SELECT * FROM
access path to
PLAN table_name;
data
Example of DML
INSERT INTO employees (first_name, last_name, department)
VALUES ('Jane', 'Smith', 'HR');
This query inserts a new record into the employees table with the first
name ‘Jane’, last name ‘Smith’, and department ‘HR’.
4. Data Control Language (DCL) in SQL
DCL (Data Control Language) includes commands such as GRANT and
REVOKE which mainly deal Open
with In
the rights, permissions, and other
App
controls of the database system. These commands are used to control
access to data in the database by granting or revoking permissions.
Common DCL Commands
Command Description Syntax
Assigns new privileges to GRANT privilege_type
a user account, allowing [(column_list)] ON
GRANT access to specific database [object_type] object_name
objects, actions, or TO user [WITH GRANT
functions. OPTION];
Removes previously
REVOKE [GRANT OPTION FOR]
granted privileges from a
privilege_type
user account, taking away
REVOKE [(column_list)] ON
their access to certain
[object_type] object_name
database objects or
FROM user [CASCADE];
actions.
Example of DCL
GRANT SELECT, UPDATE ON employees TO user_name;
This command grants the user user_name the permissions to select and
update records in the employees table.
5. Transaction Control Language (TCL) in SQL
Transactions group a set of tasks into a single execution unit. Each
transaction begins with a specific task and ends when all the tasks in the
group are successfully completed. If any of the tasks fail, the transaction
fails. Therefore, a transaction has only two results: success or failure. We
can explore more about transactions here.
Open In App
Common TCL Commands
Command Description Syntax
BEGIN BEGIN TRANSACTION
Starts a new transaction
TRANSACTION [transaction_name];
Saves all changes made
COMMIT COMMIT;
during the transaction
Undoes all changes
ROLLBACK made during the ROLLBACK;
transaction
Creates a savepoint
SAVEPOINT
SAVEPOINT within the current
savepoint_name;
transaction
Example of TCL
BEGIN TRANSACTION;
UPDATE employees SET department = 'Marketing' WHERE department
= 'Sales';
SAVEPOINT before_update;
UPDATE employees SET department = 'IT' WHERE department =
'HR';
ROLLBACK TO SAVEPOINT before_update;
COMMIT;
In this example, a transaction is started, changes are made, and a
savepoint is set. If needed, the transaction can be rolled back to the
savepoint before being committed.
Important SQL Commands
1. SELECT: Used to retrieve data from
Open InaApp
database.
2. INSERT: Used to add new data to a database.
3. UPDATE: Used to modify existing data in a database.
4. DELETE: Used to remove data from a database.
5. CREATE TABLE: Used to create a new table in a database.
6. ALTER TABLE: Used to modify the structure of an existing table.
7. DROP TABLE: Used to delete an entire table from a database.
8. WHERE: Used to filter rows based on a specified condition.
9. ORDER BY: Used to sort the result set in ascending or descending
order.
10. JOIN: Used to combine rows from two or more tables based on a
related column between them.
Conclusion
SQL commands such as DDL, DML, DCL, DQL, and TCL are foundational
for effective database management. From creating and modifying tables
with DDL commands to managing transactions with TCL commands in
SQL, understanding each type of command enhances our database skills.
Whether we are manipulating data, or managing data, SQL provides all
sets of tools. Now, with this detailed guide, we hope you have gained a
deep understanding of SQL commands, their categories, and syntax with
examples.
FAQs
What are the 5 basic SQL commands?
The five basic SQL commands are SELECT, INSERT, UPDATE,
DELETE, and CREATE. These commands allow users to retrieve, add,
modify, remove, and define database structures, forming the
foundation for database management operations.
What are the 4 types of SQL commands?
Open In App
1. DDL (Data Definition Language): Commands like CREATE,
ALTER, and DROP to define database structure.
1. DML (Data Manipulation Language): Commands like SELECT,
INSERT, UPDATE, and DELETE for data operations.
2. DCL (Data Control Language): Commands like GRANT and
REVOKE to manage permissions.
3. TCL (Transaction Control Language): Commands like COMMIT,
ROLLBACK, and SAVEPOINT to manage transactions.
What are DDL, DML, and DCL?
DDL (Data Definition Language): Used to define and manage
database schema (e.g., CREATE, ALTER).
DML (Data Manipulation Language): Handles data retrieval and
manipulation (e.g., SELECT, INSERT, UPDATE).
DCL (Data Control Language): Manages user permissions and
access control (e.g., GRANT, REVOKE).
"This course is very well structured and easy to learn. Anyone with zero
experience of data science, python or ML can learn from this. This course
makes things so easy that anybody can learn on their own. It's helping me
Open In App
a lot. Thanks for creating such a great course."- Ayushi Jain | Placed at
Microsoft
Now's your chance to unlock high-earning job opportunities as a Data
Scientist! Join our Complete Machine Learning & Data Science Program
and get a 360-degree learning experience mentored by industry experts.
Get hands on practice with 40+ Industry Projects, regular doubt solving
sessions, and much more. Register for the Program today!
Comment More info Next Article
SQL CREATE DATABASE
Similar Reads
SQL | DDL, DML, TCL and DCL
Data Definition Language (DDL), Data Manipulation Language (DML),
Transaction Control Language (TCL), and Data Control Language (DCL) for…
6 min read
Difference Between DDL and DML in DBMS
DDL is a Data Definition Language that is used to define data structures. For
example: creating a table, and altering a table are instructions in SQL. DML …
3 min read
Difference between DDL and TCL
Prerequisite – SQL Commands 1 Data Definition Language (DDL) is a set of
SQL (Structured Query Language) commands used to create, modify, and…
2 min read
Difference Between DML and TCL
Open In App
Data Manipulation Language (DML) and Transaction Control Language (TCL)
are critical subsets of SQL (Structured Query Language). Both play essentia…
4 min read
DDL Commands & Syntax
In this article, we will discuss the overview of DDL commands and will
understand DDL commands like create, alter, truncate, drop. We will cover…
3 min read
How to Maintain Audit Information For DML in SQL?
Pre-requisites: Audit Trail In today's world, data plays a vital role for any
organization. Not just for the organization but also for customers. It become…
7 min read
DQL Full Form
Data Query Language (DQL) is a component of Structured Query Language
(SQL) focused on retrieving data from databases using the SELECT…
5 min read
DCL Full Form
The full form of DCL is Data Control Language in Structured Query
Language (SQL). DCL commands are used to control privileges in the…
4 min read
DDL Full Form
DDL stands for Data Definition Language. These are the commands that are
used to change the structure of a database and database objects. For…
7 min read
TCL Full Form
Transaction Control Language (TCL) is a critical component of SQL used to
manage transactions and ensure data integrity in relational databases. By…
5 min read
Open In App
Article Tags : Databases SQL SQL-Clauses-Operators
Corporate & Communications Address:-
A-143, 9th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Pradesh
(201305) | Registered Address:- K 061,
Tower K, Gulshan Vivante Apartment,
Sector 137, Noida, Gautam Buddh
Nagar, Uttar Pradesh, 201305
Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Geeks Community
Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android Tutorial
Data Science & ML Open In App Web Technologies
Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning JavaScript
ML Maths TypeScript
Data Visualisation ReactJS
Pandas NextJS
NumPy NodeJs
NLP Bootstrap
Deep Learning Tailwind CSS
Python Tutorial Computer Science
Python Programming Examples GATE CS Notes
Django Tutorial Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths
DevOps System Design
Git High Level Design
AWS Low Level Design
Docker UML Diagrams
Kubernetes Interview Guide
Azure Design Patterns
GCP OOAD
DevOps Roadmap System Design Bootcamp
Interview Questions
School Subjects Commerce
Mathematics Accountancy
Physics Business Studies
Chemistry Economics
Biology Management
Social Science HR Management
English Grammar Finance
Income Tax
Open In App
Databases Preparation Corner
SQL Company-Wise Recruitment Process
MYSQL Resume Templates
PostgreSQL Aptitude Preparation
PL/SQL Puzzles
MongoDB Company-Wise Preparation
Companies
Colleges
Competitive Exams More Tutorials
JEE Advanced Software Development
UGC NET Software Testing
UPSC Product Management
SSC CGL Project Management
SBI PO Linux
SBI Clerk Excel
IBPS PO All Cheat Sheets
IBPS Clerk Recent Articles
Free Online Tools Write & Earn
Typing Test Write an Article
Image Editor Improve an Article
Code Formatters Pick Topics to Write
Code Converters Share your Experiences
Currency Converter Internships
Random Number Generator
Random Password Generator
DSA/Placements Development/Testing
DSA - Self Paced Course JavaScript Full Course
DSA in JavaScript - Self Paced Course React JS Course
DSA in Python - Self Paced React Native Course
C Programming Course Online - Learn C with Data Structures Django Web Development Course
Complete Interview Preparation Complete Bootstrap Course
Master Competitive Programming Full Stack Development - [LIVE]
Core CS Subject for Interview Preparation JAVA Backend Development - [LIVE]
Mastering System Design: LLD to HLD Complete Software Testing Course [LIVE]
Tech Interview 101 - From DSA to System Design [LIVE] Android Mastery with Kotlin [LIVE]
DSA to Development [HYBRID]
Placement Preparation Crash Course [LIVE]
Machine Learning/Data Science Programming Languages
Complete Machine Learning & Data Science Program - [LIVE] C Programming with Data Structures
Data Analytics Training using Excel, SQL, Python & PowerBI - C++ Programming Course
[LIVE] Java Programming Course
Data Science Training Program - [LIVE] Open In App Python Full Course
Mastering Generative AI and ChatGPT
Clouds/Devops GATE
DevOps Engineering GATE CS & IT Test Series - 2025
AWS Solutions Architect Certification GATE DA Test Series 2025
Salesforce Certified Administrator Course GATE CS & IT Course - 2025
GATE DA Course 2025
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
Open In App