NOTE :

  1. DDL (DATA DEFINITION LANGUAGE)
    1. create, update, altering attribute of database Schema
  2. DML (DATA MANIPULATION LANGUAGE)
    1. Manipulate perform crud operation, aggregate function, join tables
  3. DCL (DATA CONTROL LANGUAGE)
    1. GRANT permission and REVOKE permission access
  4. TCL (TRANSACTION CONTROL LANGUAGE)
    1. control on Transaction flow
  5. DQL (DATA QUERY LANGUAGE)
    1. both select , select with aggregate function

1. DDL (Data Definition Language)

Purpose: Defines or modifies the structure of database objects like tables, indexes, schemas, etc.

Common Commands:

Command Description
CREATE Create a new database, table, or other object
ALTER Modify an existing object (e.g., add a column)
DROP Delete an object (table, database, etc.)
TRUNCATE Remove all rows from a table (faster than DELETE)

Examples:

-- Create a table
CREATE TABLE Students (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    age INT
);

-- Add a new column
ALTER TABLE Students ADD email VARCHAR(100);

-- Delete a table
DROP TABLE Students;

-- Remove all data from table
TRUNCATE TABLE Students;


2. DML (Data Manipulation Language)

Purpose: Works with data inside the tables (CRUD operations).

Common Commands:

Command Description
INSERT Add new rows to a table
UPDATE Modify existing rows
DELETE Remove rows
SELECT Retrieve data

Examples:

-- Insert data
INSERT INTO Students (id, name, age) VALUES (1, 'Alice', 20);

-- Update data
UPDATE Students SET age = 21 WHERE id = 1;

-- Delete data
DELETE FROM Students WHERE id = 1;

-- Select data
SELECT * FROM Students;
SELECT name, age FROM Students WHERE age > 18;