patternsqlModerate
Does Microsoft SQL Server offer an Advisory Locks feature like Postgres?
Viewed 0 times
advisorypostgressqlmicrosoftlikeofferdoesserverlocksfeature
Problem
In Postgres, the Advisory Locks feature provides for arbitrary application-defined locks to be administered centrally in the database server. These locks are not related to tables or rows or such.
Does Microsoft SQL Server offers something like these Advisory Locks?
Does Microsoft SQL Server offers something like these Advisory Locks?
Solution
Application locks. They are arbitrary locks held by the engine on behalf of the app. Acquired with
sp_getapplock and released with sp_releaselock (if needed). Shared, Update, Exclusive and intent modes with the usual compatibility matrix. Can have transaction or session scope. The behavior matches the PG advisory locks in every aspect, but is a stored procedure, not a function (so it cannot be used inline in a SELECT, for instance).Context
StackExchange Database Administrators Q#176424, answer score: 11
Revisions (0)
No revisions yet.