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.
2. UPDATE¶
Used to modify existing records. Always use a WHERE clause or you will update every row! โ ๏ธ
3. DELETE¶
Used to remove specific rows.
๐จ 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¶
๐ 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
COMMITcommand. If you make a mistake, you can undo it usingROLLBACK. ๐ก๏ธ
๐ฏ 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 = 90000without 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