Interview prep · written by the FindAJobAI team

SQL Developer Interview Questions (2026) and How to Answer

By FindAJobAI Team Updated How we wrote this page

SQL developer interviews check whether you can write correct, fast database code and change production data without causing harm. Expect questions on joins, window functions, indexing and execution plans, plus stories about slow queries, deadlocks and data corrections. Most teams add a live SQL exercise where you write queries against a small schema and explain your choices aloud.

Below: 30 questions with what each one really asks and an answer outline, full sample answers to the 10 most asked, red flags to avoid and a 7-day plan.

Answering with STAR

Tell each story in four steps: the situation in a sentence, your task, the actions you took (most of the answer) and the result, with a number if you have one. Aim for about two minutes; the outlines show what to include, the details must be yours.

Behavioural questions (1–10)

How you've handled real situations. Answer each with one true story, in STAR order.

  1. 1.Tell me about a query you tuned that users had complained about.

    What they're really asking: Checks whether you diagnose performance problems from evidence, not guesses.

    Answer outline (STAR)

    • SituationUnderwriters waited about 20 seconds for a renewal screen during busy mornings.
    • TaskMake the screen fast again without changing what it returned.
    • ActionUsed Query Store to find a procedure with an unstable plan, rewrote two predicates and added a narrow index with the DBA.
    • ResultThe screen opened in under a second, and the side spreadsheets staff kept were dropped.

    Full sample answer (fictional example)

    Our underwriters complained that the renewal screen took about twenty seconds to open on busy mornings. I opened Query Store and found that the procedure behind it had two plans, one fast and one very slow, depending on which agency ran it first after a restart. I rewrote two predicates so the optimizer could use an existing index and added one narrow index after agreeing it with our DBA. I tested the change on a copy of production with a week of real parameter values. The screen now opens in under a second for every agency, and the spreadsheets staff had been keeping on the side disappeared.

  2. 2.Describe a production data correction you had to make.

    What they're really asking: Checks care and process when changing live data under pressure.

    Answer outline (STAR)

    • SituationA billing bug had written the wrong tax code on about 2,300 invoices.
    • TaskFix the rows quickly without touching any correct data.
    • ActionWrote a select to confirm the exact rows, a backup table, an update in a transaction and a rollback script, all peer reviewed.
    • ResultThe fix ran in under a minute, finance confirmed the totals and no other rows changed.

    Full sample answer (fictional example)

    A billing bug had written the wrong tax code on about 2,300 invoices, and finance needed them corrected before the monthly close. I first wrote a select that returned exactly those rows and checked the count with the finance lead. Then I copied the affected rows into a backup table, wrote the update inside a transaction and prepared a rollback script. A colleague reviewed all three scripts before I ran anything. The update finished in under a minute, I checked the row count matched before committing, and finance confirmed the totals. No other rows changed, and I attached the scripts to the ticket.

  3. 3.Tell me about a time a schema change you released caused a problem.

    What they're really asking: Checks honesty and what you changed in your process afterwards.

    Answer outline (STAR)

    • SituationA new non-null column broke an old import job that nobody had listed as a dependency.
    • TaskRestore the import and prevent similar surprises.
    • ActionAdded a default to the column within the hour, then searched all code for inserts into the table.
    • ResultThe import ran that night, and dependency searches became part of our release checklist.

    Full sample answer (fictional example)

    I once added a non-null column to a customer table, and an old import job that nobody had mentioned started failing because it inserted rows without that column. The help desk flagged it within an hour. I added a default value to the column so the job could run again, and the import completed that night. The real lesson was about dependencies, so I searched all our code and job definitions for inserts into that table and found two more callers. After that, our release checklist included a dependency search for every changed table, and we have not had a similar surprise since.

  4. 4.Describe how you agreed a data access pattern with an application team.

    What they're really asking: Checks collaboration with developers who call your database code.

    Answer outline (STAR)

    • SituationA mobile team wanted to query order tables directly with dynamic SQL from their API.
    • TaskGive them what they needed without risking performance and security.
    • ActionMet them to list the screens and filters, then wrote 6 parameterized procedures with the indexes to match.
    • ResultThey shipped on time, and the order screens stayed under 200 milliseconds after launch.

    Full sample answer (fictional example)

    A mobile team wanted to build SQL strings in their API and query our order tables directly. I was worried about injection risk and unpredictable queries on large tables, but I did not want to slow them down. I asked for a meeting and we listed every screen and filter their app needed. There were only six real patterns, so I wrote six parameterized procedures and added indexes that matched those filters. They had working endpoints within a week, they shipped on schedule, and the order screens stayed under 200 milliseconds after launch.

  5. 5.Tell me about a time you found and removed recurring deadlocks.

    What they're really asking: Checks how you handle concurrency problems that are hard to reproduce.

    Answer outline (STAR)

    • SituationThe claims system logged about 40 deadlocks a week at peak hours.
    • TaskFind the cause and stop users losing their work.
    • ActionCaptured deadlock graphs, saw two procedures updating the same tables in opposite order and aligned them.
    • ResultDeadlocks fell to near zero, and the support tickets about lost edits stopped.

    Full sample answer (fictional example)

    Our claims system logged about forty deadlocks a week, mostly at peak hours, and users were losing edits. I set up an extended events session to capture deadlock graphs and looked at a week of them. Nearly all involved two procedures that updated the claims and payments tables in opposite order. I changed one procedure so both touched the tables in the same order, and I shortened its transaction by moving a lookup outside it. After release, deadlocks fell to almost zero, and the support tickets about lost work stopped within a fortnight.

  6. 6.Tell me about a time you simplified a very complex stored procedure.

    What they're really asking: Checks whether you make code maintainable for the rest of the team.

    Answer outline (STAR)

    • SituationA 1,400-line pricing procedure had grown over years and nobody wanted to touch it.
    • TaskMake it readable and testable without changing results.
    • ActionSplit it into 5 smaller procedures, added tSQLt tests for each and compared outputs for 3 months of orders.
    • ResultResults matched, and the next change to it took a day instead of a week.

    Full sample answer (fictional example)

    We had a pricing procedure of about fourteen hundred lines that had grown for years, and developers avoided changing it. I proposed splitting it, and my manager agreed if I could prove the results stayed the same. I broke it into five smaller procedures with clear names and wrote tSQLt tests for each one. Then I ran the old and new versions against three months of real orders and compared every output row. Everything matched. The next pricing change after that took one day instead of the week similar changes used to need.

  7. 7.Describe a time you mentored a developer on SQL.

    What they're really asking: Checks whether you raise the skill of people around you.

    Answer outline (STAR)

    • SituationA new application developer kept writing queries that scanned whole tables.
    • TaskHelp him write efficient SQL without slowing his work.
    • ActionPaired with him for an hour each week on execution plans using his own queries.
    • ResultWithin two months his pull requests rarely needed index or query changes.
  8. 8.Tell me about a time you had to explain a database limit to a non-technical person.

    What they're really asking: Checks clear communication about technical trade-offs.

    Answer outline (STAR)

    • SituationA product owner wanted a search across every field of 50 million records with instant results.
    • TaskExplain what was practical and offer an option.
    • ActionShowed which fields users actually searched and proposed indexed search on those plus full-text on notes.
    • ResultShe agreed, and the search launched with response times under half a second.
  9. 9.Describe a time you archived or purged a large amount of data.

    What they're really asking: Checks careful handling of large deletes and retention rules.

    Answer outline (STAR)

    • SituationOrder tables held 180 million rows going back 12 years and backups were slowing.
    • TaskMove old data out without blocking daily work.
    • ActionAgreed retention with finance, copied old rows to a history database and deleted in small batches at night.
    • ResultBackups shrank by about a third, and no user noticed the work.
  10. 10.Tell me about a time you caught a problem in code review.

    What they're really asking: Checks attention to detail and constructive feedback.

    Answer outline (STAR)

    • SituationA colleague's update joined on a non-unique column that could match several rows.
    • TaskStop a silent data error before release.
    • ActionShowed the duplicate matches with a quick query and suggested joining on the full key.
    • ResultThe fix was made before release, and we added a uniqueness check to the review checklist.

Technical and role-skill questions (11–22)

Can you do the work itself? Think out loud and name the trade-offs.

  1. 11.What is the difference between a clustered and a nonclustered index?

    What they're really asking: Checks your core understanding of how tables are physically stored.

    Answer outline

    • A clustered index defines the order the table's rows are stored in, so a table has only one.
    • A nonclustered index is a separate structure with keys and pointers, and it can include extra columns to cover queries.
  2. 12.When would you use a window function instead of GROUP BY?

    What they're really asking: Checks fluency with analytic SQL beyond basic aggregates.

    Answer outline

    • Use a window function when you need an aggregate or ranking alongside each detail row.
    • GROUP BY collapses rows, while ROW_NUMBER, SUM OVER or LAG keep them and add the calculation.

    Full sample answer (fictional example)

    I use a window function when I need a calculation across a group but still want to keep every detail row. For example, if I need each order with the customer's total spend next to it, SUM OVER partitioned by customer gives that in one pass, while GROUP BY would collapse the orders into one row per customer. Window functions are also my default for ranking, such as finding each customer's latest order with ROW_NUMBER, and for comparisons with previous rows using LAG. I still use GROUP BY whenever the result really should be one row per group.

  3. 13.How do you read an execution plan to find the expensive part?

    What they're really asking: Checks whether you can tune with evidence from the optimizer.

    Answer outline

    • Look for operators with the highest cost, large scans, key lookups and big gaps between estimated and actual rows.
    • Check warnings such as spills or implicit conversions, then test one change at a time.
  4. 14.What is parameter sniffing and how can you deal with it?

    What they're really asking: Checks knowledge of a common cause of erratic procedure performance.

    Answer outline

    • The optimizer builds a plan for the first parameter values, which may suit later values badly.
    • Options include rewriting predicates, OPTIMIZE FOR, targeted recompiles or splitting procedures by case.

    Full sample answer (fictional example)

    When a procedure runs for the first time, the optimizer builds a plan based on the parameter values it sees, and reuses that plan afterwards. If the first call used a rare value, the plan can be terrible for common values, or the other way round. I usually confirm it by comparing plans in Query Store and testing the procedure with different values. Fixes depend on the case. Sometimes rewriting a predicate is enough, sometimes OPTIMIZE FOR a typical value works, and for very skewed data I add a targeted recompile on one statement rather than the whole procedure.

  5. 15.Explain the main transaction isolation levels you have used.

    What they're really asking: Checks your understanding of locking, consistency and concurrency.

    Answer outline

    • Read committed blocks dirty reads, repeatable read and serializable hold more locks for stricter consistency.
    • Snapshot-based levels read row versions, which reduces blocking but uses tempdb or undo space.
  6. 16.When is a cursor acceptable, and how do you usually avoid one?

    What they're really asking: Checks whether you think in sets rather than loops.

    Answer outline

    • Cursors suit small administrative tasks or calls that truly need one row at a time.
    • For data processing, I rewrite them as set-based statements, often with joins, CTEs or window functions.
  7. 17.How do you release a schema change to a large, busy table?

    What they're really asking: Checks safe change practice on tables with heavy traffic.

    Answer outline

    • Prefer changes that avoid full rewrites or long locks, such as nullable columns, and test timing on a copy.
    • Release in steps with backfills in batches, and keep a rollback script ready.

    Full sample answer (fictional example)

    I start by checking what the change will do to the table physically, because some changes rewrite every row and hold long locks. I test the change on a recent copy of production to measure how long it takes. Where possible, I choose a lighter option, such as adding a nullable column first and backfilling values in small batches at quiet times. I make sure every application using the table is ready, and I keep a rollback script prepared. On release night I watch blocking and error logs until normal traffic has returned.

  8. 18.What is the difference between a CTE, a temp table and a table variable?

    What they're really asking: Checks when you choose each structure for intermediate results.

    Answer outline

    • A CTE is a named query used within one statement and is not stored.
    • Temp tables hold data with statistics and indexes, while table variables suit small sets with fewer optimizer details.
  9. 19.How would you find duplicate rows and keep only one of each?

    What they're really asking: Checks practical data cleaning with analytic functions.

    Answer outline

    • Use ROW_NUMBER partitioned by the columns that define a duplicate, ordered by a tie-breaker.
    • Delete rows where the number is above one, after checking the count in a select first.
  10. 20.What causes a key lookup, and when is it worth removing?

    What they're really asking: Checks deeper understanding of index design trade-offs.

    Answer outline

    • It happens when a nonclustered index finds rows but lacks columns the query needs.
    • Add included columns when the query is frequent and the lookups are many, weighing write cost.
  11. 21.How do you protect database code against SQL injection?

    What they're really asking: Checks security awareness in database development.

    Answer outline

    • Use parameterized queries and procedures, and never build SQL by joining user input into strings.
    • Where dynamic SQL is needed, use sp_executesql with parameters and quote object names safely.
  12. 22.How do you test stored procedures before release?

    What they're really asking: Checks whether you treat database code like real software.

    Answer outline

    • Write unit tests with a framework such as tSQLt or pgTAP for expected outputs and edge cases.
    • Run them in a pipeline against a fresh database built from source control.

Take-home or live exercise: tips

SQL developer interviews usually include a live or take-home task: write queries against a small schema of customers, orders and products, often with ranking or running totals, then explain the indexes you would add and how you tested your answers.

  • Ask about the grain of each table and how nulls and duplicates should be treated before writing anything.
  • Talk through your approach aloud, starting with a simple correct query before optimizing it.
  • Check results with small counts or hand-worked examples, and say how you verified them.
  • Mention the index you would add for each query and the write cost it brings.

Situational questions (23–30)

Scenarios that test judgement: say what you'd do first, and why.

  1. 23.A procedure that ran in two seconds yesterday now takes two minutes. What do you check?

    What they're really asking: Checks a structured approach to sudden performance regressions.

    Answer outline

    • Compare current and previous plans in Query Store, and look at statistics updates and data volume changes.
    • Check blocking and recent deployments, then force a good plan short term while fixing the cause.
  2. 24.A manager asks you to run an urgent update directly on production. How do you respond?

    What they're really asking: Checks whether you keep safe habits when someone senior is in a hurry.

    Answer outline

    • Agree the urgency, but still confirm affected rows with a select and take a backup of them first.
    • Run it in a transaction with a second person checking, and record what was changed.

    Full sample answer (fictional example)

    I would take the urgency seriously, because there is usually a real business reason. But I would still follow a short safe routine, which only takes a few minutes. I would write a select first to confirm exactly which rows will change and check the count with the manager. Then I would copy those rows to a backup table, run the update inside a transaction and ask a colleague to look over the script. I would commit only after the row count matched. Afterwards I would record what changed in a ticket so the fix is traceable.

  3. 25.Two developers want different index designs for the same table. How do you decide?

    What they're really asking: Checks judgment based on workload evidence instead of opinion.

    Answer outline

    • Collect the real query patterns and their frequency from monitoring or the application code.
    • Test both designs on realistic data, weighing read gains against write and storage cost.
  4. 26.You inherit a database with no foreign keys and many orphan rows. What do you do?

    What they're really asking: Checks how you improve data integrity without breaking applications.

    Answer outline

    • Measure the orphans per table and find which code paths create them.
    • Clean data in reviewed batches, then add constraints one table at a time with the application team.
  5. 27.Month-end reports are blocking order entry on the same database. What do you propose?

    What they're really asking: Checks options for mixing reporting and transactional work.

    Answer outline

    • Short term, tune the heaviest report queries and schedule them away from peak hours.
    • Longer term, move reporting to a readable replica or snapshot isolation after testing.
  6. 28.A table has grown to 2 billion rows and inserts are slowing. What do you look at?

    What they're really asking: Checks scaling approaches for very large tables.

    Answer outline

    • Review indexes for unused ones, page splits from a poor clustered key and statistics age.
    • Consider partitioning by date with archiving, tested on a copy of production first.
  7. 29.An analyst says a view returns different totals than the application screen. How do you investigate?

    What they're really asking: Checks how you trace logic differences in shared data.

    Answer outline

    • Pick one record with a difference and trace it through both the view and the screen's query.
    • Agree which rule is correct with the owner, fix the wrong one and document the definition.
  8. 30.You must add a column to a table used by ten applications. How do you plan it?

    What they're really asking: Checks change management across many dependent systems.

    Answer outline

    • Search code and job definitions for every use of the table, especially SELECT star and inserts.
    • Add the column as nullable or with a default, tell owners in advance and monitor after release.

Red flags to avoid in your answers

Each one is quick to fix before the day.

  1. Answering every performance question with 'add an index'.

    Describe how you read the plan first, then choose between rewriting the query, statistics or an index with its trade-offs.

  2. Describing production fixes run without backups or review.

    Walk through your safe routine: confirming rows, backing them up, using transactions and getting a second check.

  3. Writing row-by-row loops for data processing.

    Show that you think in sets and can rewrite a cursor as a join, CTE or window function.

  4. Vague answers about isolation levels and locking.

    Prepare a clear explanation of read committed and snapshot isolation, with one blocking problem you solved.

How to prepare for a SQL developer interview in 7 days

An hour or two a day is enough; the order matters more than the length.

  1. Day 1: Joins, CTEs and window functions

    Write ten practice queries covering ranking, running totals, gaps and islands, and deduplication on sample data.

  2. Day 2: Reading execution plans

    Run slow queries on a sample database, save their plans and note scans, lookups and estimate gaps for each one.

  3. Day 3: Index design practice

    Design indexes for five common queries, then measure reads before and after with IO statistics turned on.

  4. Day 4: Locking and isolation review

    Reproduce a simple blocking chain and a deadlock on a test database, then explain how you would fix each one.

  5. Day 5: Safe data change stories

    Write three stories about data fixes, releases or incidents using situation, task, action and result.

  6. Day 6: Research the database estate

    Read the posting for engine, version and industry, and match each requirement to one example from your work.

  7. Day 7: Timed live SQL rehearsal

    Solve a timed set of four query problems aloud, then choose three questions to ask the interviewers.

Questions to ask the interviewer

Pick two or three; the answers tell you whether you want the job.

  1. Which database engine and version do you run, and are upgrades planned?
  2. How do schema changes move from development to production today?
  3. Who owns performance problems: developers, DBAs or both?
  4. What are the largest tables, and how quickly are they growing?
  5. How much of the business logic lives in stored procedures versus application code?

Preparation tips

  • Practise writing window function queries by hand, since live SQL tasks often include ranking or running totals.
  • Prepare one tuning story with the plan problem, the fix and the before-and-after timing.
  • Be ready to explain exactly how you run a data fix on production, step by step.

Prepare the general questions too: tell me about yourself, why do you want to work here? and why are you leaving? Afterwards, send a thank-you email; when the offer comes, negotiate the salary.

How we wrote this page

The FindAJobAI team wrote the questions, outlines and sample answers for SQL developer interviews. The people, employers and numbers in the samples are invented: copy the structure, and use details from your own work.

Once we track enough live SQL developer job ads, this page also shows the skills they ask for most, counted the same way as our in-demand skills report.

Last reviewed on November 1, 2026.