🗄️ DBMS Revision — MathWorks EDG Interview Prep
⏱ Time-boxed for spoken answers under 30 seconds each 🔴 = HIGHEST PRIORITY (answer these first if time is short)
🔴 1. Relational (SQL) vs Non-Relational (NoSQL)
One-line definition:
SQL databases store data in structured tables with fixed schemas; NoSQL databases store data in flexible formats (documents, key-value, graphs, columns) without a rigid schema.
Key Point / Mechanism:
- SQL: ACID-compliant, uses joins across normalized tables, best when data relationships are complex and consistency is critical (e.g., banking).
- NoSQL: built for scale, speed, and schema flexibility — trades strong consistency for high availability and horizontal scaling.
- The CAP theorem explains why: you can only fully guarantee 2 of Consistency, Availability, Partition Tolerance.
Types of NoSQL:
| Type | Example | Use Case |
|---|---|---|
| Document | MongoDB | User profiles, product catalogs |
| Key-Value | Redis | Caching, sessions |
| Column-family | Cassandra | Time-series, IoT data |
| Graph | Neo4j | Social networks, recommendation engines |
When to use which:
| Use SQL when... | Use NoSQL when... |
|---|---|
| Relationships are complex | Schema changes frequently |
| Strong consistency needed | Massive scale / high write throughput |
| Data is structured | Unstructured or semi-structured data |
| Example: Banking system | Example: Real-time analytics, social feed |
Common Follow-up:
"Can NoSQL databases be consistent?" Yes — many offer tunable consistency (e.g., Cassandra lets you choose consistency level per query), but they default to eventual consistency for performance.
🔴 2. ACID Properties
One-line definition:
ACID is a set of 4 properties that guarantee database transactions are processed reliably even in case of failures.
Each letter explained:
| Property | One-liner | Analogy |
|---|---|---|
| A — Atomicity | Transaction is all-or-nothing; if one step fails, everything rolls back | Transfer Rs.500: debit and credit both happen, or neither does |
| C — Consistency | A transaction takes the DB from one valid state to another; no rule is violated | You cannot have a negative bank balance after any transaction |
| I — Isolation | Concurrent transactions do not see each other mid-execution | Two people booking the last train seat simultaneously — only one succeeds |
| D — Durability | Once committed, data persists even if the system crashes immediately after | After you get a booking confirmation, a server restart won't erase it |
Common Follow-up:
"What is the opposite of ACID?" BASE — used in NoSQL: Basically Available, Soft state, Eventually consistent.
3. Normalization — 1NF / 2NF / 3NF
One-line definition:
Normalization is the process of organizing a database to reduce redundancy and improve data integrity by splitting data into related tables.
Each form in one sentence:
| Form | Rule | Red Flag it fixes |
|---|---|---|
| 1NF | Each column holds atomic (indivisible) values and each row is unique | A "Phone" column with "9999, 8888" in one cell |
| 2NF | Must be in 1NF + every non-key column must depend on the WHOLE primary key (no partial dependency) | Student name stored in a table whose PK is (StudentID, CourseID) — name only depends on StudentID |
| 3NF | Must be in 2NF + no non-key column depends on another non-key column (no transitive dependency) | ZIP code determining City — both in same table as StudentID |
Common Follow-up:
"Why not always normalize fully?" Over-normalization leads to too many joins, hurting read performance. Sometimes denormalization is intentional for speed (e.g., data warehouses).
4. Indexing
One-line definition:
An index is a data structure (typically a B-Tree) that the database maintains separately to allow fast lookup of rows without scanning the entire table.
Key Point / Mechanism:
- Without an index: the DB does a full table scan — O(n) for every query.
- With an index: lookup becomes O(log n) — like finding a word in a book using the index at the back instead of reading every page.
- Most common type: B-Tree index (balanced tree, great for range queries). Also: Hash index (exact match only).
Tradeoff:
Indexes speed up reads but slow down writes (INSERT/UPDATE/DELETE must also update the index). Also consume extra disk space.
Common Follow-up:
"When would you NOT add an index?" On small tables (full scan is fine), on columns with low cardinality (e.g., a boolean column — index adds no value), or on write-heavy tables where index maintenance overhead is too costly.
🔴 5. Primary Key vs Foreign Key vs Unique Key
One-line definitions:
- Primary Key: Uniquely identifies each row in a table; cannot be NULL; only one per table.
- Foreign Key: A column that references the Primary Key of another table — enforces referential integrity between tables.
- Unique Key: Ensures all values in a column are distinct; can contain one NULL; a table can have multiple unique keys.
Key Point / Mechanism:
- Primary key = identity of a record. Foreign key = link between two tables (relationship enforcer).
- Foreign key constraint prevents orphan records: you cannot insert a row referencing a non-existent parent.
- Analogy: Employee table PK = EmployeeID. Department table PK = DeptID. Employee.DeptID is a FK — ensures every employee belongs to a real department.
| Feature | Primary Key | Foreign Key | Unique Key |
|---|---|---|---|
| Uniqueness | Must be unique | References PK (must exist) | Must be unique |
| NULL allowed | No | Depends on DB | Yes (one NULL typically) |
| Count per table | Exactly one | Multiple allowed | Multiple allowed |
| Purpose | Row identity | Table relationship | Alternate uniqueness |
Common Follow-up:
"What happens if you delete a parent row that a foreign key references?" Depends on the constraint:
CASCADEdeletes child rows too;RESTRICTblocks the delete;SET NULLsets the FK to null.
DBMS Rapid-Fire Self-Test
(Try to answer each in one breath)
- What does ACID stand for? Explain Atomicity in one sentence.
- When would you choose NoSQL over SQL?
- What are the 4 types of NoSQL databases? Give one example each.
- What is a primary key vs a unique key — one key difference?
- What does a foreign key enforce?
- What is 2NF and what dependency does it eliminate?
- What is an index and what data structure does it typically use?
- What is the tradeoff of adding too many indexes?
- What does Durability in ACID mean?
- What is eventual consistency (used in NoSQL)?
Answers
- Atomicity, Consistency, Isolation, Durability. Atomicity means a transaction is all-or-nothing — if any step fails, the whole thing rolls back.
- When you need massive scale, flexible schema, high write throughput, or unstructured data (e.g., social feeds, IoT).
- Document (MongoDB), Key-Value (Redis), Column-family (Cassandra), Graph (Neo4j).
- Primary key cannot be NULL; unique key allows one NULL. Also, only one PK per table but multiple unique keys.
- Referential integrity — ensures the referenced row in the parent table actually exists.
- 2NF eliminates partial dependency — every non-key column must depend on the WHOLE composite primary key.
- A separate data structure (usually B-Tree) that enables fast row lookup without a full table scan.
- Indexes slow down writes (INSERT/UPDATE/DELETE must update every index) and consume extra storage.
- Once a transaction is committed, the data survives even a system crash immediately afterward.
- The database will become consistent eventually — at the moment of a read, you might get slightly stale data, but all nodes will sync eventually.