DBMS practice questions with answers
Practise DBMS questions at your own pace: ACID, normalisation, keys, indexes, transactions, isolation and the CAP theorem. Pick an answer to see whether you are right and why. Nothing is timed or ranked here; for that, play the Daily Quiz at 4 PM IST.
What does ACID stand for in databases?
easy
- Atomicity, Consistency, Isolation, Durability
- Accuracy, Concurrency, Integrity, Durability
- Atomicity, Concurrency, Indexing, Distribution
- Availability, Consistency, Isolation, Durability
Answer: A. Atomicity, Consistency, Isolation, Durability
Explanation: Transactions are all-or-nothing, leave the data valid, do not interfere with each other and survive crashes once committed.
A foreign key is used to:
easy
- Speed up every query
- Link a row to a row in another table and keep that reference valid
- Encrypt a column
- Make a column unique
Answer: B. Link a row to a row in another table and keep that reference valid
Explanation: Referential integrity: you cannot reference a parent row that does not exist, and deleting a referenced row is blocked or cascaded.
Which normal form requires every column to hold a single, atomic value?
easy
- 1NF
- 2NF
- 3NF
- BCNF
Answer: A. 1NF
Explanation: First normal form: no repeating groups or lists inside a cell.
What is an index mainly used for?
easy
- Saving disk space
- Speeding up lookups and sorting on its columns
- Backing up data
- Enforcing data types
Answer: B. Speeding up lookups and sorting on its columns
Explanation: Indexes (usually B+ trees) make reads faster at the cost of extra storage and slower writes.
A table is in 2NF but has a column that depends on a non-key column. Which normal form does it violate?
medium
- 1NF
- 2NF
- 3NF
- None
Answer: C. 3NF
Explanation: 3NF forbids transitive dependencies (key → A → B). Move B into its own table keyed by A.
What is a dirty read?
medium
- Reading a corrupted page from disk
- Reading data written by another transaction that has not committed yet
- Reading the same row twice and getting different values
- Reading deleted rows
Answer: B. Reading data written by another transaction that has not committed yet
Explanation: Only READ UNCOMMITTED allows dirty reads. Getting different values on a second read is a non-repeatable read.
Why do most database indexes use B+ trees rather than binary search trees?
medium
- They are easier to code
- Each node holds many keys, so the tree is shallow and needs few disk reads; leaves are linked for range scans
- They use no memory
- They never need rebalancing
Answer: B. Each node holds many keys, so the tree is shallow and needs few disk reads; leaves are linked for range scans
Explanation: A high branching factor means even millions of rows sit within 3–4 levels, matching how disks read whole pages.
Which type of relationship needs a junction (bridge) table?
medium
- One-to-one
- One-to-many
- Many-to-many
- None
Answer: C. Many-to-many
Explanation: Students and courses: a student_courses table holds pairs of foreign keys, one to each side.
What does the CAP theorem say about a distributed database during a network partition?
hard
- It can be consistent, available and partition-tolerant at once
- It must choose between consistency and availability
- It must stop accepting writes
- Partitions never happen
Answer: B. It must choose between consistency and availability
Explanation: When nodes cannot talk, either some requests are refused (consistency) or nodes answer with possibly stale data (availability).
What is a deadlock in a database, and how do databases usually resolve it?
hard
- A full disk; it is resolved by deleting logs
- Two transactions each wait for a lock the other holds; the database detects the cycle and rolls one back
- A slow query; it is resolved by adding an index
- A failed backup
Answer: B. Two transactions each wait for a lock the other holds; the database detects the cycle and rolls one back
Explanation: Applications should be ready to retry a rolled-back transaction, and lock rows in a consistent order to make deadlocks rarer.
What is write-ahead logging (WAL) for?
hard
- Compressing data
- Durability and crash recovery: changes are logged before data pages are written, so committed work can be replayed
- Speeding up SELECTs
- Replicating schemas only
Answer: B. Durability and crash recovery: changes are logged before data pages are written, so committed work can be replayed
Explanation: After a crash the database replays the log for committed transactions and undoes uncommitted ones.
Which statements about denormalisation are true? (Select all that apply)
hard
- It adds redundant data to speed up reads
- It makes writes more complex because copies must stay in sync
- It is common in analytics and NoSQL designs
- It always improves performance
Answer: A. It adds redundant data to speed up reads; B. It makes writes more complex because copies must stay in sync; C. It is common in analytics and NoSQL designs
Explanation: It is a trade-off: fewer joins at read time against more work and more risk of inconsistency at write time.