π¦ 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 |
|---|---|
| Gives a user permission to perform an action |
| 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 |
|
π DML | Data manipulation |
|
π DQL | Data querying |
|
π DCL | Permissions control |
|
βοΈ TCL | Transaction management |
|