Interview Prep
Databases Interview Questions
Schema design, indexing, transactions, and the trade-offs between relational and non-relational stores.
12 of 12 Databases questions shown. Answers are hidden by default — try each one before revealing it.
1.An orders table has a customer_id column that references customers.id. What is the primary purpose of declaring this as a foreign key constraint, rather than just storing the value with no constraint?
Easyschema-designforeign-keysintegrity
2.You create a composite index on (last_name, first_name). Which of the following queries can that index be used to efficiently narrow down, rather than scan in full?
Mediumindexingcomposite-indexquery-optimization
3.A table stores one row per order line item, with columns order_id, product_name, product_price, customer_email, and customer_phone. A customer's email is repeated on every one of their orders, and when they change their phone number some rows get updated and others don't, leaving contradictory values. What is this problem called, and what fixes it?
Mediumnormalizationschema-design
4.Which transaction isolation level is the minimum standard level that guarantees a transaction reading the same row twice will see the same value both times, assuming no explicit locking hints are used?
Hardtransactionsacidisolation-levels
5.Which scenario is generally the best fit for a schema-flexible document database over a relational database?
Mediumnosqlrelationaltrade-offs
6.A team proposes adding an index to every column of a heavily-written orders table, reasoning that a query might need it someday. What is the main downside of this approach?
Easyindexingperformance
7.When would you denormalize a schema, and why?
Mediumdenormalizationperformancetrade-offs
8.Explain the ACID properties of a database transaction using a concrete example.
Easyacidtransactions
9.How would you index this table to serve both query patterns well, and what trade-offs would you weigh?
MediumA users table has about five million rows. Two queries dominate its traffic: (1) look up a single user by exact email address during login, and (2) for internal reporting, list all users in a given country who signed up within a given date range, sorted by signup date.
indexingquery-optimization
10.What's the difference between optimistic and pessimistic concurrency control, and when would you choose each?
Hardconcurrencylockingtransactions
11.How would you decide between a relational database and a document database when starting a new service?
Mediumnosqlrelationalarchitecture
12.How would you partition or shard this table to address the slowdown, and what trade-offs come with your approach?
HardAn events table logging user activity has grown to hundreds of millions of rows. Both writes and analytical queries against recent data (the last 30 days) have slowed down significantly, even though almost nothing reads data older than a few months.
shardingpartitioningscalability