Types of SQL Commands¶
Database management system (DBMS)-e SQL-er shob dhoroner kaj ebong instruction-ke tader uddesho onujayi ei category-gulote vag kora hoy:
- DDL (Data Definition Language)
- DML (Data Manipulation Language)
- DQL (Data Query Language)
- DCL (Data Control Language)
- TCL (Transaction Control Language)
SQL commands are divided into five main categories based on their operational roles:
1. DDL (Data Definition Language)¶
- Purpose: Used to define (āϏāĻāĻā§āĻāĻžāϝāĻŧāĻŋāϤ āĻāϰāĻž), build, modify (āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāĻž), or destroy (āĻŽā§āĻā§ āĻĢā§āϞāĻž) the database structure (āĻāĻžāĻ āĻžāĻŽā§) and schema.
- Key Commands:
CREATE: Creates a new database or table from scratch.ALTER: Modifies an existing (āĻŦāĻŋāĻĻā§āϝāĻŽāĻžāύ) table's structure (e.g., adding a new column or changing data types).DROP: Deletes an entire (āϏāĻŽā§āĻĒā§āϰā§āĻŖ) table or database along with its schema and records.TRUNCATE: Rapidly purges (āĻāĻžāϞāĻŋ āĻāϰ⧠āĻĢā§āϞā§) all rows from a table while keeping the structure intact (āĻ āĻā§āώāϤ/āĻ āĻĒāϰāĻŋāĻŦāϰā§āϤāĻŋāϤ).
2. DML (Data Manipulation Language)¶
- Purpose: Used to manipulate (āϰāĻĻāĻŦāĻĻāϞ āĻāϰāĻž) and manage the actual data records (instances) stored inside tables.
- Key Commands:
INSERT: Adds new rows or records into an existing table.UPDATE: Modifies existing data values within specified (āύāĻŋāϰā§āĻĻāĻŋāώā§āĻ) rows.DELETE: Removes specific rows based on defined criteria (āĻļāϰā§āϤāĻžāĻŦāϞā§).
3. DQL (Data Query Language)¶
- Purpose: Used to retrieve (āĻā§āĻāĻā§ āĻŦā§āϰ āĻāϰāĻž/āĻāĻšāϰāĻŖ āĻāϰāĻž) and fetch relevant data from the database. Although some textbooks group this under DML, it is widely recognized as a distinct (āϏā§āĻŦāϤāύā§āϤā§āϰ/āĻāϞāĻžāĻĻāĻž) category.
- Key Command:
SELECT: Extracts (āϤā§āϞ⧠āĻāύā§) and filters data matching specified conditions (e.g.,SELECT * FROM Customers WHERE City = 'Dhaka';).- Note: Solves the file system problem of "Difficulty in Accessing Data."
4. DCL (Data Control Language)¶
- Purpose: Controls user privileges (āĻŦāĻŋāĻļā§āώ āĻ āϧāĻŋāĻāĻžāϰ) and access permissions (āĻ āύā§āĻŽāϤāĻŋāϏāĻŽā§āĻš) to protect database security.
- Key Commands:
GRANT: Gives a user permission to perform specific operations (āĻāĻžāϰā§āϝāĻā§āϰāĻŽ) on tables.REVOKE: Withdraws (āĻĒā§āϰāϤā§āϝāĻžāĻšāĻžāϰ āĻāϰ⧠āύā§āĻā§āĻž) or cancels permissions previously given to a user.- Note: Solves the file system problem of "Security Problems" by enforcing granular (āϏā§āĻā§āώā§āĻŽ/āύāĻŋāϰā§āĻĻāĻŋāώā§āĻ) access limits.
5. TCL (Transaction Control Language)¶
- Purpose: Manages transactions (āϞā§āύāĻĻā§āύāϏāĻŽā§āĻš/āĻāĻžāĻā§āϰ āϧāĻžāĻĒ) in a database to ensure consistency (āϏāĻžāĻŽāĻā§āĻāϏā§āϝāϤāĻž) and prevent data corruption.
- Key Commands:
COMMIT: Permanently (āϏā§āĻĨāĻžāϝāĻŧā§āĻāĻžāĻŦā§) saves all changes made during the current transaction.ROLLBACK: Reverts (āĻĒā§āϰā§āĻŦāĻžāĻŦāϏā§āĻĨāĻžāϝāĻŧ āĻĢāĻŋāϰāĻŋāϝāĻŧā§ āύā§āϝāĻŧ/Undo āĻāϰā§) data changes back to the previous state if an error or system crash occurs.SAVEPOINT: Creates an intermediate (āĻŽāϧā§āϝāĻŦāϰā§āϤā§/āϏāĻžāĻŽāϝāĻŧāĻŋāĻ) checkpoint inside a transaction to roll back partially.- Note: Solves the file system problem of "Atomicity of Updates" by preventing half-finished actions.
Summary Table¶
| Category | Full Form | Primary Role | Common Commands |
|---|---|---|---|
| DDL | Data Definition Language | Creates and alters (āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰā§) database structures | CREATE, ALTER, DROP, TRUNCATE |
| DML | Data Manipulation Language | Manages and edits stored records | INSERT, UPDATE, DELETE |
| DQL | Data Query Language | Queries and retrieves (āĻāĻšāϰāĻŖ āĻāϰā§) data | SELECT |
| DCL | Data Control Language | Manages access permissions (āĻ āύā§āĻŽāϤāĻŋ) and security | GRANT, REVOKE |
| TCL | Transaction Control Language | Handles transaction safety and recovery (āĻĒā§āύāϰā§āĻĻā§āϧāĻžāϰ) | COMMIT, ROLLBACK, SAVEPOINT |