SQL Fundamentals — The Questions Interviewers Always Ask First
✅ Pro Tip
Why this file exists: Patterns (SQL_01–SQL_06) test problem-solving. But before that, interviewers test foundational understanding. If you fumble ACID or can't explain normalization, you won't reach the coding round. Format: Every topic follows — Definition → Simple Explanation → Analogy → Code → Interview Tip → What NOT to say.
SECTION 1: ACID PROPERTIES
Definition (1 line each)
| Property | Definition |
|---|---|
| Atomicity | A transaction is all-or-nothing — every statement succeeds, or none do. |
| Consistency | A transaction moves the database from one valid state to another — all rules/constraints are satisfied. |
| Isolation | Concurrent transactions behave as if they ran one after another. |
| Durability | Once committed, the data survives crashes, power failures, and restarts. |
Simple Explanation
Think of a bank transfer — you move ₹5000 from Account A to Account B.
| Property | What it means for the transfer |
|---|---|
| Atomicity | Either BOTH the debit from A AND credit to B happen, or NEITHER happens. No half-transfers. |
| Consistency | Total money before = total money after. The system never shows ₹5000 vanished into thin air. |
| Isolation | If someone checks balances mid-transfer, they see either the before-state or the after-state — never the debit without the credit. |
| Durability | Once the bank says "transfer complete," even if the server crashes 1 second later, the transfer is permanent. |
Real-world Analogy
ACID is like a legal contract:
- Atomicity = The contract is either fully signed by both parties or it's void.
- Consistency = The contract can't violate any laws.
- Isolation = Two contracts being signed simultaneously don't interfere with each other.
- Durability = Once signed and filed, a fire in the building