Sql Server Interview Questions Deadlock Indexing 2025 Interview Questions & Answers

30 questions available

Q1:

What is the difference between a deadlock and a blocking chain?

Mid

Answer

Blocking = one session waiting on a resource. Deadlock = circular wait (A waits for B, B waits for A). SQL Server detects deadlocks using the lock monitor and kills the victim.
Q2:

What causes the Key Lookup operator and how do you eliminate it?

Mid

Answer

Occurs when bookmark lookup is needed to fetch missing columns. Eliminate by creating a covering index with INCLUDE columns.
Q3:

Why do deadlocks commonly occur between updates on non-covering indexes?

Mid

Answer

Because SQL Server must lock the index row and the base table row. Different access paths cause circular dependencies ? deadlocks.
Q4:

Explain the difference between Update Lock (U) and Exclusive Lock (X).

Mid

Answer

Update lock prevents deadlocks by acquiring a U lock first, then converting to X. Two sessions cannot both hold X, but they CAN both request U, avoiding conflict.
Q5:

Why can NOLOCK increase deadlocks?

Mid

Answer

NOLOCK scans do not acquire shared locks but still get blocked by schema modification locks. Also cause lock escalation indirectly due to longer scans.
Q6:

What is a Latch vs a Lock?

Mid

Answer

Lock = logical protection for rows/pages. Latch = physical protection for in-memory structures like buffer pages. Latch contention = internal engine bottleneck.
Q7:

How does RCSI reduce deadlocks?

Mid

Answer

Readers use version store in tempdb instead of locking ? no shared locks ? fewer deadlocks.
Q8:

Why can RCSI increase tempdb usage and cause slowdowns?

Mid

Answer

It stores row versions in tempdb. High write workloads ? tempdb I/O pressure ? version cleanup delays.
Q9:

What is the Ghost Cleanup process?

Mid

Answer

Deleted rows become ghosted and cleaned asynchronously. Slow cleanup causes index bloat, fragmentation, and lock waits.
Q10:

What is the difference between Seek, Scan, and SARGability?

Mid

Answer

Seek = targeted lookup Scan = entire range/table SARGable = predicate can be used for seeks. Non-SARGable examples: WHERE CONVERT(...) or WHERE SUBSTRING(...).
Q11:

What causes Page Split storms and how do you prevent them?

Mid

Answer

Page splits occur when inserting into a full page in a non-sequential index. Fix: Lower fill factor Use sequential keys (IDENTITY / NEWSEQUENTIALID)
Q12:

Why are GUIDs dangerous in clustered indexes?

Mid

Answer

Random insert pattern ? fragmentation ? page splits ? hot latch contention.
Q13:

What is Parameter Sniffing and how do you fix it?

Mid

Answer

SQL caches a plan based on first parameter. Fixes: OPTION (RECOMPILE) Optimize for hint Use local variables Query Store automatic tuning
Q14:

How does Query Store automatically solve regressions?

Mid

Answer

It compares CPU/Duration of plans and forces the better plan automatically.
Q15:

What is Write-Ahead Logging (WAL)?

Mid

Answer

SQL Server writes log records to the transaction log before modifying data pages. Ensures durability and crash recovery.
Q16:

Why does the presence of a scalar UDF slow down queries dramatically?

Mid

Answer

Pre SQL Server 2019: scalar UDF = row-by-row execution. SQL 2019+ inlines UDF inside query for set-based execution.
Q17:

What is a Hash Spill in a Hash Join or Hash Aggregate?

Mid

Answer

Occurs when memory grant is insufficient ? spill to tempdb ? heavy I/O ? slow query.
Q18:

What is the difference between a Forwarded Record and a Row Overflow?

Mid

Answer

Forwarded record = heap update that moves row ? pointer stored in original location. Row overflow = variable-length columns stored off-row due to exceeding 8KB.
Q19:

Why do heaps often cause performance issues?

Mid

Answer

Heaps suffer from: forwarded records random access no guaranteed order Clustered indexes provide stable structure.
Q20:

What triggers Lock Escalation?

Mid

Answer

When SQL Server exceeds lock thresholds (~5000 locks) ? escalates row/page locks to table lock ? blocking.
Q21:

How do filtered indexes reduce deadlocks and improve performance?

Mid

Answer

Smaller index size ? fewer pages ? fewer locks ? fewer conflicting write paths. Filtered indexes also allow highly selective optimizations for partial data sets.
Q22:

Why can a nonclustered index update slow down INSERT-heavy workloads?

Mid

Answer

Each index requires: extra write extra latch extra log record. More NC indexes = slower writes and higher contention.
Q23:

How does SQL Server choose a deadlock victim?

Mid

Answer

SQL Server picks the session with the lowest rollback cost. Configurable using: SET DEADLOCK_PRIORITY LOW | NORMAL | HIGH.
Q24:

Why does enabling Snapshot Isolation sometimes increase deadlocks?

Mid

Answer

Writers still take locks, but readers now compete for version cleanup. High version store pressure ? tempdb allocation contention ? indirect deadlocks.
Q25:

Explain the difference between RID, Key Lock, Page Lock, and HoBT Lock.

Mid

Answer

RID = row in heap Key Lock = row in index Page Lock = entire 8KB page HoBT = index partition or B-tree substructure.
Q26:

What causes Bookmark Lookup deadlocks?

Mid

Answer

Bookmark lookup locks the index row (shared) and base row (exclusive). Another session can lock these in opposite order ? circular deadlock.
Q27:

Why do MERGE statements cause more deadlocks than separate INSERT/UPDATE?

Mid

Answer

MERGE accesses source and target tables in unpredictable order. Competing locks ? higher deadlock probability vs separate operations.
Q28:

How does table partitioning reduce deadlocks?

Mid

Answer

Operations target individual partitions. Reduces hot spots, lock contention, and access collisions.
Q29:

What is a Missing Index Request and why can it be dangerous?

Mid

Answer

Optimizer suggests missing index for a single query. Adding blindly causes: duplicate indexes high write overhead plan regression. Always evaluate before creating.
Q30:

What is a latch-free index (BW-Tree) and does SQL Server use it?

Mid

Answer

A BW-Tree supports lock-free/latch-free concurrency. Used in SQL Server Hekaton (In-Memory OLTP) for extremely high throughput.