SQL COMMAND

Quick Answer — Types of SQL Commands

The 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).

SQL Command Categories — DDL, DML, DQL, DCL, TCL

Each category serves a specific purpose in database management. Below is a quick breakdown with definitions and examples.

DDL — Data Definition

Defines or modifies schema (tables, views, indexes).

CREATE • ALTER • DROP • TRUNCATE

DML — Data Manipulation

Handles data changes (insert, update, delete).

INSERT • UPDATE • DELETE

DQL — Data Query

Retrieves information from tables.

SELECT

DCL — Data Control

Controls user access & permissions.

GRANT • REVOKE

TCL — Transaction Control

Manages transactions and recovery.

COMMIT • ROLLBACK • SAVEPOINT

Summary: DDL → structure, DML → data change, DQL → data read, DCL → access control, TCL → transactions.

DDL Commands in SQL (Create • Alter • Drop • Truncate • Rename)

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.

Common DDL Commands (with purpose & examples)
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 with constraints
CREATE TABLE Orders (
  Id INT PRIMARY KEY,
  CustomerId INT NOT NULL,
  Amount DECIMAL(10,2) CHECK (Amount >= 0)
);
Add an index
CREATE INDEX idx_orders_customer ON Orders(CustomerId);
TRUNCATE vs DELETE
-- Remove all rows (fast, resets identity in many DBs)
TRUNCATE TABLE Orders;

-- Remove selected rows (can ROLLBACK)
DELETE FROM Orders WHERE Amount = 0;

DML, DQL, DCL & TCL — Quick Examples for Data Analysis

Use these sub-languages correctly during analytics workflows: change data (DML), query data (DQL), control access (DCL), and manage transactions (TCL).

DML — Data Manipulation Language

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).

DQL — Data Query Language

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.

DCL — Data Control Language

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.

TCL — Transaction Control Language

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.

Key Differences — DELETE vs TRUNCATE vs DROP, Is ALTER DDL or DML?, DCL vs TCL

Instantly answer the most searched questions with concise definitions and production-style snippets.

DELETE vs TRUNCATE vs DROP

  • DELETE (DML): removes selected rows, supports WHERE, generally logged, can ROLLBACK.
  • TRUNCATE (DDL-ish): removes all rows quickly; keeps table structure; often resets identity; rollback depends on engine/tx.
  • DROP (DDL): removes the object (table/schema) permanently — structure and data.
-- 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;

Is 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;

DCL vs TCL

  • DCL — Data Control: users/permissions (GRANT, REVOKE).
  • TCL — Transaction Control: commit/rollback state (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

Quick FAQs

Which commands are DDL?

CREATE, ALTER, DROP, TRUNCATE, RENAME (engine-specific variations exist).

Does TRUNCATE reset identity?

Often yes (e.g., SQL Server), but check your DBMS docs. It does not fire row-level triggers.

Can I ROLLBACK a DROP?

Typically no. DROP removes the object definition. Restore from backup or use point-in-time recovery if supported.

Examples by DDL, DML, DQL, DCL & TCL

Copy-paste ready snippets for each category, followed by practice tasks to test your understanding.

DDL — Data Definition Language

-- 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.

DML — Data Manipulation Language

-- 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).

DQL — Data Query Language

-- 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.

DCL — Data Control Language

-- 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.

TCL — Transaction Control Language

-- 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.

Practice Tasks

  1. Create a table Products(Id, Name, Price DECIMAL(10,2) CHECK (Price >= 0)) and add an index on Name. (DDL)
  2. Insert 3 products, then update one price by +15% and delete one product. (DML)
  3. Write a query to show total count of products by price band: <500, 500-1000, >1000 (use CASE + GROUP BY). (DQL)
  4. Grant SELECT on Products to role analyst and revoke UPDATE. (DCL)
  5. Wrap your DML in a transaction. If any step fails, ROLLBACK; otherwise COMMIT. (TCL)

DDL vs DML vs DCL vs TCL vs DQL — Quick Comparison

Short, scannable table designed for featured snippets: each category’s purpose and common commands/examples.

Types of SQL Commands (Summary)
Category Purpose (1-line) Common Commands / Examples
DDL — Data Definition Create/alter/drop structure (tables, indexes, views, schemas). CREATE ALTER DROP TRUNCATEe.g., CREATE TABLE …
DML — Data Manipulation Insert/update/delete row data inside tables. INSERT UPDATE DELETE MERGEe.g., UPDATE … SET …
DQL — Data Query Retrieve/query data for analysis & reporting. SELECTe.g., SELECT … FROM … WHERE …
DCL — Data Control Grant or revoke permissions & access control. GRANT REVOKEe.g., GRANT SELECT ON …
TCL — Transaction Control Manage transactions (commit/rollback/savepoint). COMMIT ROLLBACK SAVEPOINTe.g., BEGIN; … COMMIT;

DELETE vs TRUNCATE vs DROP — Quick Differences

Three similar-looking commands with very different effects. Use this fast reference to choose the right one.

Row-level removal vs whole-table reset vs object drop
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;

SQL Command Categories — Visual Flow

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.

DDL Data Definition

Create & modify structure

Tables, indexes, views, schemas.

CREATE ALTER DROP TRUNCATE

DML Data Manipulation

Insert, update, delete rows

Change the data within tables.

INSERT UPDATE DELETE MERGE

DQL Data Query

Query & analyze data

Retrieve rows with filters, joins, groups.

SELECT

DCL Data Control

Permissions & security

Allow/deny operations on objects.

GRANT REVOKE

TCL Transaction Control

Commit or undo changes

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.

SQL Commands MCQ — DDL vs DML vs DQL vs DCL vs 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.

    📚 Categories of SQL Commands – Complete Classification with Examples

    SQL (Structured Query Language) commands are categorized into five major types based on their function in the database system:

    • 📘 DDL (Data Definition Language): Used to define and modify database structures such as tables and indexes.
      Examples: CREATE, ALTER, DROP, TRUNCATE
    • ✏️ DML (Data Manipulation Language): Deals with inserting, updating, and deleting data within tables.
      Examples: INSERT, UPDATE, DELETE
    • 📊 DQL (Data Query Language): Retrieves data from one or more tables.
      Example: SELECT
    • 🔐 DCL (Data Control Language): Controls access to data by granting or revoking permissions.
      Examples: GRANT, REVOKE
    • 🔁 TCL (Transaction Control Language): Manages changes made by DML statements and maintains the integrity of the database.
      Examples: COMMIT, ROLLBACK, SAVEPOINT

    💡 Pro Tip: Understanding these categories is essential for writing optimized, secure, and organized SQL queries — especially in real-world data analytics and database design!

    📊 Types of SQL Commands – Full Forms, Examples & Use Cases

    SQL commands are categorized into five major types based on their functionality. Understanding these categories helps organize your SQL learning and practice effectively.

    • 1. DDL – Data Definition Language: Deals with table structure.
      CREATE, ALTER, DROP, TRUNCATE, COMMENT
    • 2. DML – Data Manipulation Language: Used to insert, update, and delete data.
      INSERT, UPDATE, DELETE
    • 3. DCL – Data Control Language: Manages access permissions.
      GRANT, REVOKE
    • 4. TCL – Transaction Control Language: Controls transactions and their states.
      COMMIT, ROLLBACK, SAVEPOINT
    • 5. DQL – Data Query Language: Retrieves data.
      SELECT

    💡 SEO Tip:

    Use keywords like “types of SQL commands,” “DDL vs DML,” and “SQL full form with examples” for better search visibility and higher impressions.

    🧠 SQL Quiz — DROP vs DELETE vs TRUNCATE

    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?

    🚀 Take Your SQL Skills to the Next Level

    📘 Explore Additional SQL Tutorials and Real-World Practice

    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.

    SQL FAQs — Quick Answers

    Short, scannable answers to the most searched SQL questions. Designed for **featured snippets** & **PAAs**.

    What is the difference between DDL and DML?

    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.

    Is SELECT DML or DQL?

    SELECT is part of DQL (Data Query Language). It retrieves data; it doesn’t modify rows.

    Which SQL command is fastest: DELETE, TRUNCATE, or DROP?

    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.

    Is ALTER DDL or DML?

    ALTER is DDL; it modifies schema (e.g., add/drop columns), not row data.

    Does TRUNCATE reset identity values?

    In many databases (e.g., SQL Server), TRUNCATE resets identity/auto-increment. Behavior can vary—always check your DBMS docs.

    Can I roll back DROP or TRUNCATE?

    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 Master Program in Data Science

    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

    ⭐ Student Reviews (Google)

    See what students say about Vista Academy — Data Science. Real ratings collected on Google.

    4.9
    out of 5
    312+ Google reviews
    • ✔️ Hands-on projects & case studies
    • ✔️ Mentorship & placement support
    • ✔️ Python, SQL, ML, TensorFlow

    Last updated: Aug 22, 2025 — Update the rating & count to match your live Google listing.

    Vista Academy – 316/336, Park Rd, Laxman Chowk, Dehradun – 248001
    📞 +91 94117 78145 | 📧 thevistaacademy@gmail.com | 💬 WhatsApp
    💬 Chat on WhatsApp: Ask About Our Courses