HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Manually deciding locking mode in MSSQL

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
modemssqlmanuallylockingdeciding

Problem

In MSSQL, when a lock is acquired with a statement, the locking mode is decided by the engine not by the programmer. Is there a way to force the engine to use a specified Locking Mode (i.e. Row Lock)?

Solution

Sure, there are plenty of table hints, like:

  • PAGLOCK



  • ROWLOCK



  • TABLOCK



  • TABLOCKX



However, you should use these with extreme caution. There are very few cases where the average programmer knows better than the engine, and forcing hints can cause more problems than they solve.

Context

StackExchange Database Administrators Q#198017, answer score: 8

Revisions (0)

No revisions yet.