Data Definition Language (DDL) πΒΆ
Prerequisites: Database Basics (Logic Snippet)
Mentor's Note: DDL is about the Structure, not the data. Think of it as building the house itself before you move the furniture in! π‘
π The Scenario: The Architect's Blueprint ποΈΒΆ
Imagine you are building a new luxury apartment complex.
- CREATE: You design the Blueprint (Number of rooms, floor plan). You are building the structure. ποΈ
- ALTER: You decide to add a Balcony to every room later. You are changing the existing structure. π οΈ
- DROP: The building is old and dangerous. you Demolish it entirely. π₯
- The Result: You are managing the "Container," not the people living inside. β
π Key DDL CommandsΒΆ
1. CREATEΒΆ
Used to create a new table or database object.
2. ALTERΒΆ
Used to modify an existing object (add/remove columns).
3. DROPΒΆ
Deletes the table and ALL its data permanently.
π¨ Visual Logic: The Schema LifecycleΒΆ
graph LR
A[Design π] -- CREATE --> B[New Table π]
B -- ALTER --> C[Updated Structure π οΈ]
C -- DROP --> D[Deleted / Empty Space π¨]
π» Implementation: The Schema LabΒΆ
π Sample Dry RunΒΆ
| Command | Action | Data Inside? | Structure Changes? |
|---|---|---|---|
CREATE |
Build box π¦ | No | New box added. |
ALTER |
Add divider π | Unaffected | Box modified. |
DROP |
Burn box π₯ | DESTROYED | Box removed. |
π Complexity AnalysisΒΆ
- Execution: DDL commands are Auto-Committed in Oracle. This means once you run them, you cannot "Undo" (Rollback) the change! β οΈ Be very careful.
π― Practice Lab π§ͺΒΆ
Task: The Employee Setup
Task: Create a table EMPLOYEES with emp_id, emp_name, and join_date. Then, add a salary column using ALTER.
Hint: Use VARCHAR2 for names and DATE for dates. π‘
π‘ Interview Tip πΒΆ
"Interviewers often ask: 'What is the difference between DROP and TRUNCATE?' Answer: DROP deletes the structure + data. TRUNCATE deletes ONLY the data but keeps the empty structure!"
π‘ Pro Tip: "Good design is a lot like clear thinking made visual." - Edward Tufte