📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What are key-range locks in SQL Server, and when do they appear?

Senior Theory Advanced

🎯 Key points

  • Lock the gap between keys, not just existing rows
  • Only under SERIALIZABLE or HOLDLOCK
  • Modes like RangeS-S, RangeS-U, RangeI-N
  • Prevent phantom inserts
  • Need an index on the predicate; otherwise wide locking
  • Increase blocking and deadlock risk

⏱ 30-second answer

Key-range locks protect the gap between index keys so no other session can insert a row that would change the result of a range read. They appear only under SERIALIZABLE (or the HOLDLOCK hint). Modes such as RangeS-S, RangeS-U and RangeI-N combine a range part and a key part. They prevent phantoms and make upserts safe, but they need a suitable index (otherwise far more is locked), increase blocking, and are a common cause of deadlocks.

🔍 What the interviewer is checking

Checks understanding of how SERIALIZABLE prevents phantoms and why it increases blocking.

↩ Usually asked after

More in SQL Features

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me