• 防止用户同时使用一个存储过程


    create proc mytest
    as
    begin
     DECLARE @res INT
        EXEC @res = sp_getapplock
                    @Resource = 'mytest',
                    @LockMode = 'Exclusive',
        @LockOwner = 'Session'
     if @res = 1
     begin
      EXEC @res = sp_releaseapplock
                                @Resource = 'mytest',
           @LockOwner = 'Session'
       return;
     end
     PRINT 'get lock'
     waitfor delay '00:01'
            EXEC @res = sp_releaseapplock
                                @Resource = 'mytest',
           @LockOwner = 'Session'
            PRINT 'release lock'
    end

  • 相关阅读:
    64_q2
    64_q1
    64_p10
    64_p9
    64_p8
    64_p7
    64_p6
    64_p5
    64_p4
    64_p3
  • 原文地址:https://www.cnblogs.com/accumulater/p/6146805.html
Copyright © 2020-2023  润新知