Database Management System (DBMS) / SQL(STRUCTURED QUERY LANGUAGE)

Types of SQL Commands

πŸ“¦ DDL β€” Data Definition Language

Defines and modifies the structure of a database.

  • 🧱 CREATE β€” Builds new tables, databases, or views

  • 🧱 ALTER β€” Changes an existing structure (e.g., adding a column)

  • 🧱 DROP β€” Permanently deletes a table or database

  • 🧱 TRUNCATE β€” Clears every record from a table while keeping its structure intact

πŸ“Œ Example:

CREATE TABLE students (
  id INT,
  name VARCHAR(50)
);

πŸ“ DML β€” Data Manipulation Language

Manipulates the data stored inside tables.

  • πŸ–ŠοΈ INSERT β€” Adds new records

  • ✏️ UPDATE β€” Modifies existing records

  • πŸ—‘οΈ DELETE β€” Removes specific records

πŸ“Œ Example:

INSERT INTO students (id, name) VALUES (1, 'Swastika');

πŸ” DQL β€” Data Query Language

Retrieves data from a database.

  • πŸ”Ž SELECT β€” Fetches records based on given conditions

πŸ“Œ Example:

SELECT name FROM students WHERE id = 1;

πŸ” DCL β€” Data Control Language

Controls who can access data β€” who can read it, change it, or remove it entirely.

Main commands:

Command

Purpose

GRANT

Gives a user permission to perform an action

REVOKE

Takes that permission back

🎯 Real-life example: Picture a school database where you're the Principal β€” the admin. You want the teacher to only view student records, and the clerk to be able to add or update them, but neither should be able to delete anything. GRANT and REVOKE are exactly how you'd set that up.

πŸ“Œ Example:

-- Let the clerk add and update student records
GRANT INSERT, UPDATE ON students TO clerk;

-- Let the teacher view records only
GRANT SELECT ON students TO teacher;

-- Take away the clerk's ability to update
REVOKE UPDATE ON students FROM clerk;

βš™οΈ TCL β€” Transaction Control Language

Manages transactions β€” groups of operations that succeed or fail together.

  • βœ… COMMIT β€” Makes changes permanent

  • ❌ ROLLBACK β€” Undoes changes made before a commit

  • ⏸️ SAVEPOINT β€” Marks a point you can roll back to

  • πŸ” SET TRANSACTION β€” Configures how a transaction behaves

πŸ“Œ Example:

BEGIN;
UPDATE students SET name = 'Anya' WHERE id = 1;
ROLLBACK;

βœ… Summary

Category

Purpose

Key Commands

πŸ“¦ DDL

Structure management

CREATE, ALTER, DROP, TRUNCATE

πŸ“ DML

Data manipulation

INSERT, UPDATE, DELETE

πŸ” DQL

Data querying

SELECT

πŸ” DCL

Permissions control

GRANT, REVOKE

βš™οΈ TCL

Transaction management

COMMIT, ROLLBACK, SAVEPOINT