CREATE PROCEDURE [dbo].[ben_testing] AS BEGIN SET NOCOUNT ON; declare @RC int; begin tran exec @RC = sp_getapplock @Resource='testingLock', @LockMode='Exclusive', @LockOwner='Transaction' select @@SPID [session_id], @RC [return code], GETDATE() waitfor delay '00:00:05' commit END
上面的sp_getapplock可以避免SP同時執行,以保護資料更新時的問題。
Reference: Prevent multiple users from running the same SQL Server stored procedure at the same time
No comments:
Post a Comment