Skip to content

Data Manipulation Language (DML) ๐Ÿš€

Mentor's Note: If DDL is building the house, DML is moving the furniture in, changing the sofa, or throwing out old trash. It's how you manage the actual Information! ๐Ÿ’ก


๐ŸŒŸ The Scenario: The Warehouse Manager ๐Ÿ“ฆ

Imagine you manage a grocery warehouse.

  • INSERT: A truck arrives with 50 crates of Apples ๐ŸŽ. You add them to your inventory record.
  • UPDATE: The price of Milk ๐Ÿฅ› goes up. You change the label on the shelf.
  • DELETE: A box of Bananas ๐ŸŒ is rotten. You remove it from the records.
  • The Result: Your inventory stays current and accurate. โœ…

๐Ÿ“– Key DML Commands

1. INSERT

Used to add new rows to a table.

INSERT INTO students (id, name, age) 
VALUES (101, 'Vishnu', 25);

2. UPDATE

Used to modify existing records. Always use a WHERE clause or you will update every row! โš ๏ธ

UPDATE students 
SET age = 26 
WHERE id = 101;

3. DELETE

Used to remove specific rows.

DELETE FROM students 
WHERE id = 101;


๐ŸŽจ Visual Logic: The DML Impact

graph TD
    A[Empty Table ๐Ÿ“‹] -- INSERT --> B[Table with Data ๐ŸŽ]
    B -- UPDATE --> C[Corrected Data ๐Ÿ’Ž]
    C -- DELETE --> D[Specific Row Removed ๐Ÿ—‘๏ธ]

๐Ÿ’ป Implementation: The Inventory Lab

-- ๐Ÿ›’ Scenario: Stocking a new product
-- ๐Ÿš€ Action: Inserting a laptop record

INSERT INTO products (pid, pname, stock)
VALUES (5001, 'Dell XPS', 10);

-- ๐Ÿ›๏ธ Outcome: A new row appears in the table.
-- ๐Ÿ›’ Scenario: Flash Sale!
-- ๐Ÿš€ Action: Discounting all laptops

UPDATE products
SET price = price * 0.9
WHERE pname LIKE '%Laptop%';

๐Ÿ“Š Sample Dry Run (DELETE)

Command: DELETE FROM users WHERE status = 'Inactive'

ID Name Status Action
1 Vishnu Active KEEP โœ…
2 John Inactive DELETE ๐Ÿ—‘๏ธ
3 Sara Active KEEP โœ…

๐Ÿ“ˆ Technical Analysis

  • Transaction Control: In Oracle, DML changes are not permanent until you run the COMMIT command. If you make a mistake, you can undo it using ROLLBACK. ๐Ÿ›ก๏ธ

๐ŸŽฏ Practice Lab ๐Ÿงช

Task: Update the Grades

Task: You have a GRADES table. Student 105 was given B by mistake. Change it to A. Then, delete all records where the student has Left the school. Hint: Use UPDATE and DELETE with specific WHERE clauses. ๐Ÿ’ก


๐Ÿ’ก Interview Tip ๐Ÿ‘”

"Interviewers love the 'Where Clause' question. What happens if you run UPDATE employees SET salary = 90000 without a WHERE clause? Answer: Everyone in the company gets the same salary! ๐Ÿ˜ฑ Always double-check your WHERE clause."


๐Ÿ’ก Pro Tip: "The only thing constant is change." - Heraclitus


โ† Back: DDL | Next: PL/SQL Foundations โ†’