Oracle DML Basics 📝
Mentor's Note: Creating the table was building the room. DML is the act of moving furniture in, rearranging it, or throwing it away. But remember: in Oracle, changes aren't permanent until you say so! 💡
🌟 The Scenario: The Office Move 📦
- INSERT: Bringing a new desk into the room.
- UPDATE: Changing the label on a folder.
- DELETE: Removing an old chair that broke.
💻 1. INSERT (Add Data)
-- Standard Insert
INSERT INTO employees (id, name, salary)
VALUES (101, 'Rahul', 50000);
-- Bulk Insert from another table
INSERT INTO graduates_archive
SELECT * FROM students WHERE status = 'Finished';
💻 2. UPDATE (Modify Data) ✏️
Warning: Always use a WHERE clause!
UPDATE employees
SET salary = salary * 1.10 -- 10% raise
WHERE department_id = 20;
💻 3. DELETE (Remove Data) ❌
Warning: This is permanent!
DELETE FROM employees
WHERE id = 105;
🏗️ Architect's Note: Transactions & Redo Logs 🛡️
Oracle is a Transactional database.
- The Architect's Secret: When you run DML, Oracle doesn't change the data on the disk immediately. It writes to the Redo Log first.
- The Safety Net: Use
COMMITto save permanently orROLLBACKto undo your mistakes! - Architecture Tip: Keep your transactions short. Long transactions hold "Locks" on the rows, which can slow down other users.