DBMS · All levels
DBMS Interview Preparation: Keys, Normalisation, Transactions and Indexing
Revise the database theory asked in campus and developer interviews — keys, normal forms, ACID, isolation levels, indexing and SQL vs NoSQL.
Published 4 Dec 20263 min read
DBMS questions test whether you understand how data is organised and kept consistent. Answer with a definition, a short example and, where possible, a trade-off.
Keys
| Key | Meaning |
|---|---|
| Super key | Any set of columns that uniquely identifies a row |
| Candidate key | A minimal super key (no column can be removed) |
| Primary key | The candidate key chosen to identify rows; unique and not NULL |
| Alternate key | A candidate key not chosen as primary |
| Foreign key | A column referencing another table's key, enforcing referential integrity |
| Composite key | A key made of more than one column |
ER modelling basics
Entities become tables; attributes become columns; relationships are one-to-one, one-to-many or many-to-many. A many-to-many relationship (students ↔ courses) is implemented with a junction table (enrollments(student_id, course_id)).
Normalisation
Normalisation reduces redundancy and update anomalies.
- 1NF — each column holds atomic values; no repeating groups.
- 2NF — 1NF, and no non-key column depends on only part of a composite key.
- 3NF — 2NF, and no non-key column depends on another non-key column (no transitive dependency).
- BCNF — for every functional dependency X → Y, X is a super key.
Example: storing dept_name in an employees table that already has dept_id creates a transitive dependency (emp_id → dept_id → dept_name). Moving department names to a departments table brings it to 3NF.
Q: When would you denormalise? For read-heavy reporting where joins are expensive — accepting some redundancy for faster queries.
Transactions and ACID
A transaction is a group of operations that succeed or fail together (e.g. debit one account, credit another).
- Atomicity — all or nothing.
- Consistency — moves the database from one valid state to another, respecting constraints.
- Isolation — concurrent transactions don't interfere in unintended ways.
- Durability — once committed, changes survive crashes.
Concurrency problems and isolation levels
| Problem | What happens |
|---|---|
| Dirty read | Reading another transaction's uncommitted change |
| Non-repeatable read | Re-reading a row gives a different value |
| Phantom read | Re-running a query returns new rows |
| Isolation level | Prevents |
|---|---|
| Read Uncommitted | Nothing |
| Read Committed | Dirty reads |
| Repeatable Read | Dirty + non-repeatable reads |
| Serializable | All three |
Higher isolation means fewer anomalies but less concurrency. Default levels differ between databases.
Indexing
An index is a separate data structure (commonly a B+ tree) that lets the database find rows without scanning the whole table.
- Clustered index — determines the physical order of rows; one per table.
- Non-clustered index — a separate structure pointing to rows; many allowed.
Trade-offs: indexes speed up reads but slow down inserts/updates and use storage. They help on selective columns used in WHERE, JOIN and ORDER BY; they help little on columns with very few distinct values.
Views, stored procedures and triggers
- View — a saved query presented as a virtual table.
- Stored procedure — precompiled SQL logic stored in the database.
- Trigger — code that runs automatically on
INSERT,UPDATEorDELETE.
SQL vs NoSQL
| SQL (relational) | NoSQL | |
|---|---|---|
| Schema | Fixed, defined upfront | Flexible |
| Model | Tables & relations | Document, key-value, column, graph |
| Strength | Complex queries, strong consistency | Horizontal scale, flexible data |
| Examples | PostgreSQL, MySQL | MongoDB, Redis, Cassandra |
Choose based on data shape, consistency needs and access patterns — not trends.
Practice checklist
- Normalise a sample "orders" spreadsheet to 3NF and draw the tables.
- Explain a bank transfer using ACID properties.
- Describe a scenario where an index makes a query slower overall.
- #dbms
- #databases
- #cs-fundamentals