Skip to main content

Delivery & Infrastructure

SQL & Database Interview Questions and Answers

Review SQL and database interview questions on joins, indexes, transactions, normalization, query plans, locking, and reliable schema design.

  1. 01

    How do INNER JOIN and LEFT JOIN differ?

    Question codesql
    SELECT customers.name, orders.id
    FROM customers
    INNER JOIN orders ON orders.customer_id = customers.id;

    INNER JOIN returns rows with matching records on both sides. LEFT JOIN keeps every row from the left side and uses null values where no right-side match exists.

    Answer codesql
    SELECT customers.name, orders.id
    FROM customers
    LEFT JOIN orders ON orders.customer_id = customers.id;
    
    -- Customers without an order remain, with a NULL order id.
  2. 02

    What does a database index improve and what does it cost?

    An index can reduce the work needed to find, join, or order rows, depending on the query and index structure. It consumes storage and adds maintenance cost to writes, so indexes should follow observed access patterns.

  3. 03

    What do ACID transaction properties describe?

    Atomicity, consistency, isolation, and durability describe how a database protects a transaction and its committed result. Isolation level determines which concurrent effects are visible and involves correctness and performance tradeoffs.

  4. 04

    Why normalize a relational schema?

    Normalization reduces duplication and update anomalies by representing facts in appropriate relations. Selective denormalization can improve read patterns, but should preserve a clear source of truth.

  5. 05

    How would you investigate a slow SQL query?

    Inspect the actual query plan, row estimates, scans, joins, filters, sorting, data distribution, and lock waits. Improve the query, schema, or index based on measured behavior and verify it with representative data.

  6. 06

    What causes database deadlocks?

    A deadlock occurs when transactions wait on resources held by each other in a cycle. Keep transactions short, access resources in a consistent order, use suitable indexes, and safely retry the transaction selected as the victim.

Continue preparing

Related interview guides

Need delivery capability?

Pair technical understanding with the right specialist.

Explore hiring roles
Have a quick question?Chat on WhatsAppSQL & Database Interview Questions and Answers | Quinoid