Data Manipulation Language (DML) πΒΆ
Prerequisites: Data Definition Language (DDL)
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