Interview questionsUpdated 12 Oct 2026 · Team InterviewPlan

SQL Developer Interview Questions and Answers

SQL developer interviews go beyond writing queries. Panels test how you design schemas, tune slow queries, use indexes wisely and keep data consistent under concurrent load. These questions reflect what SQL Server, Oracle and PostgreSQL developers are asked in 2026, with model answers from real database work.

What interviewers test in a SQL developer interview

Most loops include live query writing on a sample schema, conceptual questions on indexes and transactions, and a performance tuning scenario. Senior roles add schema design and production troubleshooting.

Interviewers look for correctness first, then performance awareness: whether you think about indexes, cardinality and how a query will behave with millions of rows.

  • Querying: joins, subqueries, CTEs, window functions and set operators
  • Design: normalisation, keys, constraints and data types
  • Performance: indexes, execution plans, statistics and sargability
  • Programmability: stored procedures, functions, triggers and error handling
  • Concurrency: transactions, isolation levels, locking and deadlocks

Technical topics to revise

Practise on a realistic schema with orders, customers, products and employees. Write each query, then check its execution plan and see how adding an index changes it.

  • INNER, LEFT, RIGHT, FULL and CROSS joins, self joins and anti joins
  • ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD and running totals with SUM OVER
  • Recursive CTEs for hierarchies like employee and manager
  • Clustered, non-clustered, covering and filtered indexes
  • Execution plans: seeks versus scans, key lookups and estimated versus actual rows
  • ACID, isolation levels and snapshot isolation
  • TRY CATCH, transactions in stored procedures and MERGE
  • Partitioning and archiving large tables

How to structure your answers

For query questions, confirm the expected output and edge cases such as ties, nulls and duplicates before writing. Then write the query step by step and explain why it is correct.

For tuning stories, give before and after numbers, such as execution time, logical reads or CPU, and explain the root cause you found.

How InterviewPlan AI helps you prepare

SQL mock interviews ask query, indexing and tuning questions and give feedback on your reasoning. Coding help lets you review practice queries, and Resume AI highlights performance improvements you delivered.

Interview Copilot provides live speaker-labelled transcription and resume-grounded answer drafts in under a second. Once hired, SQL Job Support gives live expert-plus-AI help with tickets and query tuning in your first 90 days, at $5 per hour with 200 AI credits included.

Questions and model answers

9 questions you are likely to hear.

  1. What is the difference between WHERE and HAVING?

    Why they ask: A fundamentals check on query processing order.

    Sample answer: WHERE filters rows before grouping and aggregation, while HAVING filters groups after aggregation. So WHERE cannot use aggregate functions, but HAVING can. For example, to find customers with more than five orders in 2026, I filter the order date in WHERE and then use HAVING COUNT(*) greater than 5 after GROUP BY customer_id. Putting row-level filters in WHERE is also more efficient, because fewer rows are grouped. In one report I moved a date filter from HAVING to WHERE and the query ran several times faster on a large orders table.

  2. Explain clustered and non-clustered indexes.

    Why they ask: Index knowledge is central to SQL performance.

    Sample answer: A clustered index defines the physical order of rows in the table, so there can be only one, and the leaf level is the data itself. In SQL Server it is often the primary key. A non-clustered index is a separate structure with the key columns and a pointer to the row, and a table can have many. If a non-clustered index does not contain all needed columns, the engine does key lookups, which become expensive at volume. I add included columns to create covering indexes for frequent queries, but avoid too many indexes on write-heavy tables because each insert must update them.

  3. Write a query to get a running total of sales by date.

    Why they ask: Window functions are asked in almost every SQL interview.

    Sample answer: I would aggregate daily sales first, then apply a window function: SELECT sale_date, daily_total, SUM(daily_total) OVER (ORDER BY sale_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_total FROM a CTE that groups sales by sale_date. Specifying ROWS instead of the default RANGE avoids unexpected results with duplicate dates and performs better in SQL Server. If the running total should reset each month or per region, I would add PARTITION BY. I used this pattern for a finance dashboard showing month-to-date revenue against target.

  4. How do you approach tuning a slow query?

    Why they ask: This is the core practical skill for SQL developers.

    Sample answer: I first capture the actual execution plan and IO and time statistics. I look for table scans on large tables, key lookups, big differences between estimated and actual rows, which point to stale statistics or parameter sniffing, and expensive sorts or hash spills. I check that predicates are sargable, for example no functions wrapped around indexed columns in WHERE. Fixes include adding or adjusting indexes, rewriting the query, updating statistics or breaking it into steps with temp tables. In one stored procedure, rewriting a YEAR() filter as a date range let it use an index and cut run time from 45 seconds to under 2.

  5. What are transaction isolation levels, and which problems do they prevent?

    Why they ask: Concurrency correctness is essential in transactional systems.

    Sample answer: Isolation levels control how transactions see each other's changes. Read Uncommitted allows dirty reads. Read Committed, the default in SQL Server, prevents dirty reads but allows non-repeatable reads. Repeatable Read prevents those, but phantom rows can still appear. Serializable prevents phantoms too but increases blocking. Snapshot isolation and Read Committed Snapshot use row versioning so readers do not block writers. For a reporting workload that was blocking order inserts, enabling Read Committed Snapshot removed most blocking without changing application code, after we checked tempdb capacity.

  6. How do you handle deadlocks?

    Why they ask: Deadlocks are a common production issue in busy databases.

    Sample answer: A deadlock happens when two transactions each hold a lock the other needs, and the database kills one as the victim. I capture deadlock graphs with Extended Events, using the system_health session in SQL Server, to see which statements and resources are involved. Common fixes are accessing tables in the same order in all procedures, keeping transactions short, adding indexes so queries lock fewer rows and using row versioning isolation. I also add retry logic for deadlock errors in the application. In one system, reordering updates in two procedures eliminated daily deadlocks during batch processing.

  7. Write a query to find employees who earn more than their managers.

    Why they ask: Self joins are a classic interview test.

    Sample answer: I would self join the employees table: SELECT e.name AS employee, e.salary, m.name AS manager, m.salary AS manager_salary FROM employees e INNER JOIN employees m ON e.manager_id = m.employee_id WHERE e.salary > m.salary. The inner join excludes employees without a manager, such as the CEO, which is correct here. I would confirm whether salary can be null, since comparisons with null return unknown and those rows would drop out. For a full reporting chain rather than direct managers only, I would use a recursive CTE.

  8. When would you use a temp table versus a table variable or CTE?

    Why they ask: This tests practical understanding of query optimisation tools.

    Sample answer: A CTE is just a named query that improves readability and enables recursion; it is not stored, so if referenced several times it may run several times. Temp tables are stored in tempdb, support indexes and have statistics, so they are good for larger intermediate results used multiple times. Table variables have limited statistics, which historically led to poor estimates, so I use them for small sets. In a complex month-end procedure, materialising an intermediate result of a few million rows into an indexed temp table cut run time significantly compared to a chain of nested CTEs.

  9. Tell me about a database problem you solved that had business impact.

    Why they ask: This shows ownership and real-world value.

    Sample answer: At a retail client, the nightly inventory sync took around five hours and often overran into store opening times. I traced it to a cursor-based stored procedure that processed products row by row with multiple lookups. I rewrote it as set-based logic with MERGE statements, added covering indexes for the lookup tables and batched updates in chunks of 50,000 rows to limit log growth and locking. The job dropped to under 40 minutes. Store managers stopped seeing stale stock levels in the morning, which reduced manual stock checks.

FAQ

Questions people ask about sql developer.

Which database should I prepare for SQL developer interviews?

Prepare the one in the job description, usually SQL Server, Oracle or PostgreSQL. Core SQL transfers, but know the specifics like T-SQL versus PL/SQL syntax, execution plan tools and how each database handles concurrency.

How long are SQL coding rounds?

Usually 30 to 60 minutes with two to five problems of increasing difficulty, often on a shared editor or whiteboard. Practise writing queries without running them and explaining edge cases out loud.

Do SQL developers need to know ETL tools?

Many roles include SSIS, Azure Data Factory or Informatica. Even if not required, understanding how data loads work, including incremental loads and error handling, makes you a stronger candidate and helps you answer data quality questions.

Can InterviewPlan AI help me practise SQL interviews?

Yes. Mock interviews and coding help use AI credits to practise queries and tuning scenarios with feedback. The free plan includes 100 AI credits and 5 live Copilot minutes, no card required.

P.S.

Reading helps. Practising out loud helps more.

Start free with 5 live minutes and 100 AI credits for Resume AI, Job Search, Auto-Apply, mock interviews and Behavioral Coach.