SQL Commands_ DDL, DQL, DML, DCL and TCL With Examples
SQL Commands_ DDL, DQL, DML, DCL and TCL With Examples
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
Open In App
Command Description Syntax
RENAME TABLE
Rename an object existing
RENAME old_table_name TO
in the database
new_table_name;
Example of DDL
In this example, a new table called employees is created with columns for
employee ID, first name, last name, and hire date.
DQL Command
Example of DQL
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.
Open In App
Command Description Syntax
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
This query inserts a new record into the employees table with the first
name ‘Jane’, last name ‘Smith’, and department ‘HR’.
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
This command grants the user user_name the permissions to select and
update records in the employees table.
Open In App
Common TCL Commands
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;
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
"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
Get hands on practice with 40+ Industry Projects, regular doubt solving
sessions, and much more. Register for the Program today!
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
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
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
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]
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
Open In App