28-07-2025
SQL DDL Queries (Data Definition
Language)
Managing Database Structure
Presented by: Dr. Yatendra Sahu
What is DDL in SQL?
• DDL stands for Data Definition Language.
• Used to define and manage database
structures.
• Includes operations like creating, altering,
dropping tables.
• DDL commands automatically commit
changes to the database.
1
28-07-2025
DDL Commands Overview
• CREATE – Create new tables, databases,
indexes.
• ALTER – Modify existing tables.
• DROP – Delete tables or databases.
• TRUNCATE – Remove all records but keep the
structure.
• RENAME – Rename a table.
CREATE Command
• Creates new database objects (tables, databases,
views, etc.)
• Example:
• CREATE TABLE Students (
• StudentID INT PRIMARY KEY,
• Name VARCHAR(50),
• Age INT,
• Course VARCHAR(50)
• );
2
28-07-2025
CREATE DATABASE Example
• Creates a new database.
• Example:
• CREATE DATABASE UniversityDB;
ALTER Command
• Modifies an existing table.
• Examples:
• ALTER TABLE Students ADD Email
VARCHAR(100);
• ALTER TABLE Students MODIFY Age SMALLINT;
• ALTER TABLE Students DROP COLUMN Email;
3
28-07-2025
DROP Command
• Deletes a database object permanently.
• Examples:
• DROP TABLE Students;
• DROP DATABASE UniversityDB;
• Warning: Cannot be rolled back!
TRUNCATE Command
• Removes all rows from a table but retains the
structure.
• Example:
• TRUNCATE TABLE Students;
• Faster than DELETE; cannot be rolled back in
many RDBMS.
4
28-07-2025
RENAME Command
• Changes the name of a table.
• Example:
• RENAME TABLE Students TO Learners;
• Note: Syntax may vary across databases.
Key Differences
• DROP – Deletes structure and data
permanently.
• TRUNCATE – Deletes data only, keeps
structure.
• DELETE – Deletes selected rows, can be rolled
back.
• Use DDL carefully as many changes are
irreversible!
5
28-07-2025
Summary
• DDL defines structure, not data content.
• Key commands: CREATE, ALTER, DROP,
TRUNCATE, RENAME.
• DDL operations are auto-committed and often
irreversible.
Practice Suggestions
• Create sample databases and tables.
• Use ALTER to add/modify/drop columns.
• Compare TRUNCATE vs DELETE performance.
• Test DDL in different RDBMS environments
(MySQL, PostgreSQL, etc.)
6
28-07-2025
Q&A
• Any questions?
• Let’s review your doubts or real examples!