DDL — Data Definition
Defines or modifies schema (tables, views, indexes).
CREATE • ALTER • DROP • TRUNCATE
Table of Contents
ToggleThe 5 categories of SQL commands are: DDL (create/alter/drop objects), DML (insert/update/delete data), DQL (query with SELECT), DCL (GRANT, REVOKE), and TCL (COMMIT, ROLLBACK, SAVEPOINT).
Each category serves a specific purpose in database management. Below is a quick breakdown with definitions and examples.
Defines or modifies schema (tables, views, indexes).
CREATE • ALTER • DROP • TRUNCATE
Handles data changes (insert, update, delete).
INSERT • UPDATE • DELETE
Retrieves information from tables.
SELECT
Controls user access & permissions.
GRANT • REVOKE
Manages transactions and recovery.
COMMIT • ROLLBACK • SAVEPOINT
✅ Summary: DDL → structure, DML → data change, DQL → data read, DCL → access control, TCL → transactions.
DDL (Data Definition Language) defines and modifies database structure—tables, views, indexes, schemas.
✅ Remember: DDL changes the schema, not just the data. Many engines auto-commit DDL.
Command | Purpose | Example |
---|---|---|
CREATE | Create objects (table, view, index, schema) |
CREATE TABLE Employees (Id INT PRIMARY KEY, Name VARCHAR(60));
|
ALTER | Change structure (add/modify/drop column/index) |
ALTER TABLE Employees ADD Email VARCHAR(120);
|
DROP | Delete object permanently (structure + data) |
DROP TABLE Employees;
|
TRUNCATE | Remove all rows, keep table (faster than DELETE) |
TRUNCATE TABLE Employees;
|
RENAME | Rename object (syntax varies by DBMS) |
ALTER TABLE Employees RENAME TO Staff;
|
CREATE TABLE Orders ( Id INT PRIMARY KEY, CustomerId INT NOT NULL, Amount DECIMAL(10,2) CHECK (Amount >= 0) );
CREATE INDEX idx_orders_customer ON Orders(CustomerId);
-- Remove all rows (fast, resets identity in many DBs) TRUNCATE TABLE Orders; -- Remove selected rows (can ROLLBACK) DELETE FROM Orders WHERE Amount = 0;
Use these sub-languages correctly during analytics workflows: change data (DML), query data (DQL), control access (DCL), and manage transactions (TCL).
Change row data inside tables (INSERT, UPDATE, DELETE, MERGE).
-- Insert a new order INSERT INTO Orders (Id, CustomerId, Amount) VALUES (101, 7, 1599.00); -- Update an existing order UPDATE Orders SET Amount = Amount * 1.10 WHERE Id = 101; -- Delete cancelled orders DELETE FROM Orders WHERE Status = 'Cancelled';
Tip: Wrap critical DML in a transaction (see TCL).
Retrieve and analyze data with SELECT (joins, filters, groups).
-- Top 5 products by total revenue SELECT p.ProductName, SUM(oi.Quantity * oi.UnitPrice) AS TotalSales FROM OrderItems oi JOIN Products p ON p.Id = oi.ProductId GROUP BY p.ProductName ORDER BY TotalSales DESC LIMIT 5;
Tip: Use GROUP BY + ORDER BY for ranked insights.
Grant or revoke permissions to keep data secure.
-- Allow analysts to read sales data GRANT SELECT ON Sales TO analyst; -- Remove insert permission from trainee REVOKE INSERT ON Sales FROM trainee;
Tip: Pair DCL with roles/groups for easier governance.
Control commit/rollback to keep data consistent.
-- Transfer with atomicity BEGIN; UPDATE Accounts SET Balance = Balance - 500 WHERE Id = 1; UPDATE Accounts SET Balance = Balance + 500 WHERE Id = 2; COMMIT; -- or ROLLBACK if any step fails
Tip: Use SAVEPOINT for partial rollbacks within long flows.
✅ At a glance: DML changes rows, DQL reads rows, DCL controls who can do what, TCL confirms or undoes changes.
Instantly answer the most searched questions with concise definitions and production-style snippets.
WHERE
, generally logged, can ROLLBACK.-- Delete matching rows (undoable in a transaction) DELETE FROM Orders WHERE Status = 'Cancelled'; -- Empty table (fast), keep structure TRUNCATE TABLE Orders; -- Remove table entirely (irreversible) DROP TABLE Orders;
ALTER
DDL or DML?ALTER is DDL because it changes schema (structure), not row data.
-- Add a column (schema change) ALTER TABLE Employees ADD Email VARCHAR(120); -- Rename table (syntax may vary by DBMS) ALTER TABLE Employees RENAME TO Staff;
GRANT
, REVOKE
).COMMIT
, ROLLBACK
, SAVEPOINT
).-- DCL: manage privileges GRANT SELECT ON Sales TO analyst; REVOKE INSERT ON Sales FROM trainee; -- TCL: atomic unit of work BEGIN; UPDATE Accounts SET Balance = Balance - 500 WHERE Id = 1; UPDATE Accounts SET Balance = Balance + 500 WHERE Id = 2; COMMIT; -- ROLLBACK if any step fails
CREATE, ALTER, DROP, TRUNCATE, RENAME (engine-specific variations exist).
Often yes (e.g., SQL Server), but check your DBMS docs. It does not fire row-level triggers.
Typically no. DROP removes the object definition. Restore from backup or use point-in-time recovery if supported.
Copy-paste ready snippets for each category, followed by practice tasks to test your understanding.
-- Create table with PK and default CREATE TABLE Customers ( Id INT PRIMARY KEY, Name VARCHAR(80) NOT NULL, Email VARCHAR(120) UNIQUE, CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Add a new column ALTER TABLE Customers ADD Phone VARCHAR(20); -- Create an index for faster lookups CREATE INDEX idx_customers_email ON Customers(Email);
Use DDL for structure: tables, indexes, constraints.
-- Insert customers INSERT INTO Customers (Id, Name, Email) VALUES (1,'Asha','asha@example.com'), (2,'Rohan','rohan@example.com'); -- Update email domain UPDATE Customers SET Email = REPLACE(Email, '@example.com', '@vista.com') WHERE Email LIKE '%@example.com'; -- Delete test data DELETE FROM Customers WHERE Name = 'Test';
Wrap critical DML in transactions (see TCL).
-- Count customers by email domain SELECT SPLIT_PART(Email,'@',2) AS Domain, COUNT(*) AS Cnt FROM Customers GROUP BY Domain ORDER BY Cnt DESC; -- Find customers created in the last 7 days SELECT * FROM Customers WHERE CreatedAt >= CURRENT_DATE - INTERVAL '7 days' ORDER BY CreatedAt DESC;
Use GROUP BY + ORDER BY for ranked insights.
-- Grant read-only access to reporting user GRANT SELECT ON Customers TO analyst; -- Revoke write permissions REVOKE INSERT, UPDATE, DELETE ON Customers FROM trainee;
Prefer roles over individual users for scale.
-- Safe email domain migration (atomic) BEGIN; UPDATE Customers SET Email = REPLACE(Email, '@vista.com', '@thevistaacademy.com'); SAVEPOINT after_email_update; -- If needed: -- ROLLBACK TO SAVEPOINT after_email_update; COMMIT; -- finalize changes
Use SAVEPOINTs to recover mid-transaction.
Products(Id, Name, Price DECIMAL(10,2) CHECK (Price >= 0))
and add an index on Name
. (DDL)<500
, 500-1000
, >1000
(use CASE
+ GROUP BY
). (DQL)Products
to role analyst
and revoke UPDATE. (DCL)Short, scannable table designed for featured snippets: each category’s purpose and common commands/examples.
Category | Purpose (1-line) | Common Commands / Examples |
---|---|---|
DDL — Data Definition | Create/alter/drop structure (tables, indexes, views, schemas). |
CREATE
ALTER
DROP
TRUNCATE
— e.g., CREATE TABLE …
|
DML — Data Manipulation | Insert/update/delete row data inside tables. |
INSERT
UPDATE
DELETE
MERGE
— e.g., UPDATE … SET …
|
DQL — Data Query | Retrieve/query data for analysis & reporting. |
SELECT
— e.g., SELECT … FROM … WHERE …
|
DCL — Data Control | Grant or revoke permissions & access control. |
GRANT
REVOKE
— e.g., GRANT SELECT ON …
|
TCL — Transaction Control | Manage transactions (commit/rollback/savepoint). |
COMMIT
ROLLBACK
SAVEPOINT
— e.g., BEGIN; … COMMIT;
|
Three similar-looking commands with very different effects. Use this fast reference to choose the right one.
Command | What it does (1-line) | Key behavior |
---|---|---|
DELETE (DML) | Removes selected rows from a table. |
Supports WHERE ; logged; can ROLLBACK; triggers fire; slower for huge tables.
|
TRUNCATE (DDL-ish) | Removes all rows, keeps structure. |
No WHERE ; very fast; often resets identity; may bypass row triggers; rollback depends on engine/tx.
|
DROP (DDL) | Removes the object itself (table/schema). | Deletes structure + data; typically not recoverable without backup; fastest way to remove a table. |
-- Row-level DELETE FROM Orders WHERE Status = 'Cancelled';
-- All rows, keep table TRUNCATE TABLE Orders;
-- Remove object DROP TABLE Orders;
A one-glance map of the five SQL sub-languages and what they do: DDL → structure, DML → data changes, DQL → querying, DCL → permissions, TCL → transactions.
Tables, indexes, views, schemas.
CREATE
ALTER
DROP
TRUNCATE
Change the data within tables.
INSERT
UPDATE
DELETE
MERGE
Retrieve rows with filters, joins, groups.
SELECT
Allow/deny operations on objects.
GRANT
REVOKE
Ensure atomicity & consistency.
COMMIT
ROLLBACK
SAVEPOINT
Flow idea: DDL defines structure → then you use DML to change data → read it via DQL → secure it with DCL → safeguard changes with TCL.
Answer 20 questions covering SQL command categories, differences like DELETE vs TRUNCATE vs DROP, permissions with DCL, and transactions with TCL. Click Submit Quiz to see your score and explanations.
SQL (Structured Query Language) commands are categorized into five major types based on their function in the database system:
💡 Pro Tip: Understanding these categories is essential for writing optimized, secure, and organized SQL queries — especially in real-world data analytics and database design!
SQL commands are categorized into five major types based on their functionality. Understanding these categories helps organize your SQL learning and practice effectively.
CREATE, ALTER, DROP, TRUNCATE, COMMENT
INSERT, UPDATE, DELETE
GRANT, REVOKE
COMMIT, ROLLBACK, SAVEPOINT
SELECT
Use keywords like “types of SQL commands,” “DDL vs DML,” and “SQL full form with examples” for better search visibility and higher impressions.
Pick one option per question. Answers lock after a click. Your score appears automatically at the end.
1) Which SQL command removes all records from a table, but keeps the table structure?
2) Which SQL command permanently deletes a table from the database?
3) Which command can use a WHERE
clause to delete selected rows?
4) Which command is slowest when deleting a large number of rows due to logging?
5) Which command automatically commits and cannot be rolled back in most RDBMS?
Now that you’ve mastered the LIKE operator and wildcards, it’s time to expand your knowledge. Learn advanced SQL concepts, practice with real datasets, and build job-ready expertise:
These resources will guide you through complex SQL concepts with real-world practice. Keep learning, keep practicing, and move closer to becoming a job-ready SQL expert.
Short, scannable answers to the most searched SQL questions. Designed for **featured snippets** & **PAAs**.
DDL (Data Definition Language) changes structure—tables, views, indexes (e.g., CREATE, ALTER, DROP). DML (Data Manipulation Language) changes row data—INSERT, UPDATE, DELETE, MERGE.
SELECT is part of DQL (Data Query Language). It retrieves data; it doesn’t modify rows.
For removing data: TRUNCATE is usually fastest for clearing all rows (keeps table). DELETE is row-by-row (slower but precise, supports WHERE). DROP removes the object itself (table + data) and is not for partial data removal.
ALTER is DDL; it modifies schema (e.g., add/drop columns), not row data.
In many databases (e.g., SQL Server), TRUNCATE resets identity/auto-increment. Behavior can vary—always check your DBMS docs.
DROP removes the object definition—typically not recoverable without backup. TRUNCATE rollback depends on engine/transaction settings; in many systems it’s DDL-like and auto-committing.
Vista Academy’s Best Data Science Course in Dehradun provides in-depth training in Machine Learning, Artificial Intelligence, Big Data Analytics, and Predictive Modeling. Gain hands-on experience with Python, R, SQL, and TensorFlow — and build a strong career foundation in Data Science & AI.
📍 Address: Vista Academy, 316/336, Park Rd, Laxman Chowk, Dehradun, Uttarakhand 248001
See what students say about Vista Academy — Data Science. Real ratings collected on Google.
Last updated: Aug 22, 2025 — Update the rating & count to match your live Google listing.