From some recent testing and reading I've done, it seems the "X" (exclusive) name part of XLOCK is misleading. It in fact doesn't lock any more than UPDLOCK. If it were exclusive, it would prevent external SELECTs, which it doesn't.
I cannot see either from reading or from testing and difference between the two.
The only time XLOCK creates an exclusive lock is when used with TABLOCK. My first question is "why only at this granularity?"
Further, I came across a blog that states the following:
However, watch out for XLOCK hint. SQL Server will effectively ignore XLOCK hint! There's an optimization where SQL Server check whether the data has changed since the oldest open transaction. If not, then an xlock is ignored. This makes xlock hints basically useless and should be avoided.
Has anyone run across this phenomenon?
Based on what I'm seeing, it seems this hint should be ignored.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…