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

Data Modification Language (DML)

DML is a category of SQL used to modify the data inside existing tables.

It allows you to add, update, and delete records.


⚙️ Base Setup (ONE Code Block)

We will use THIS data for all examples below ⬇️

-- Base Table
CREATE TABLE students (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50),
    grade VARCHAR(2)
);

📌 We will use ONLY this table and data for all examples below
No repeated CREATE TABLE or INSERT again.


➕ INSERT – Add New Records

Used to insert new rows into a table.

📌 Basic Example:

INSERT INTO students (name, grade)
VALUES ('Swastika', 'A');

📌 Insert multiple rows:

INSERT INTO students (name, grade)
VALUES 
  ('Anya','B'),
  ('Riya','A');

✏️ UPDATE – Modify Existing Records

Used to change data in one or more rows.

📌 Update one row:

UPDATE students
SET grade = 'A+'
WHERE id = 1;

📌 Update all rows:

UPDATE students
SET grade = 'B';

⚠️ Be careful — without WHERE, it updates every row


🗑️ DELETE – Remove Records

Used to delete rows from a table.

📌 Delete one row:

DELETE FROM students
WHERE id = 1;

📌 Delete all rows (but keep structure):

DELETE FROM students;

⚠️ Use TRUNCATE (from DDL) if you want faster full-table deletion


✅ Summary Table

DML Command

Purpose

Example

➕ INSERT

Add new rows

INSERT INTO table VALUES (...)

✏️ UPDATE

Modify existing rows

UPDATE table SET column = value

🗑️ DELETE

Remove rows from table

DELETE FROM table WHERE condition