USE TestSystem
BEGIN TRANSACTION test1
EXEC [sp_getapplock] 'AppSourceName' , 'Exclusive'
WAITFOR DELAY '00:00:5'
PRINT 'done appLock 1'
COMMIT TRANSACTION test1
USE TestSystem
BEGIN TRANSACTION test2
EXEC [sp_getapplock] 'AppSourceName' , 'Exclusive'
PRINT 'done second!'
COMMIT TRANSACTION test2
四个point
1. use TestSystem,必须是同数据库
2. AppSourceName,同资源名称
3. Exclusive,锁定模式相同
4. Begin transaction 必须在事务里面(事务提交/回滚的时候,会自动释放锁)