Skip to content

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. 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?

    Easy

    schema-designforeign-keysintegrity

  2. 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?

    Medium

    indexingcomposite-indexquery-optimization

  3. 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?

    Medium

    normalizationschema-design

  4. 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?

    Hard

    transactionsacidisolation-levels

  5. 5.Which scenario is generally the best fit for a schema-flexible document database over a relational database?

    Medium

    nosqlrelationaltrade-offs

  6. 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?

    Easy

    indexingperformance

  7. 7.When would you denormalize a schema, and why?

    Medium

    denormalizationperformancetrade-offs

  8. 8.Explain the ACID properties of a database transaction using a concrete example.

    Easy

    acidtransactions

  9. 9.How would you index this table to serve both query patterns well, and what trade-offs would you weigh?

    Medium

    A 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. 10.What's the difference between optimistic and pessimistic concurrency control, and when would you choose each?

    Hard

    concurrencylockingtransactions

  11. 11.How would you decide between a relational database and a document database when starting a new service?

    Medium

    nosqlrelationalarchitecture

  12. 12.How would you partition or shard this table to address the slowdown, and what trade-offs come with your approach?

    Hard

    An 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

← All interview prep categories