߳ͬʱݿͬһ¼ͻᵼºһ¼ǰһӶһЩ⡣
磺
һƱϵͳһƱͻÿһγƱƱͼһ
龰
ܹ300ƱƱ㣬ǡͬһʱƱIJȲѯƱȻһ
һsql䣺
1
2
3
4
5
6
7
8
9
declare @count as int
begin tran
select @count=count from ttt
WAITFOR DELAY '00:00:05' --ģⲢӳ5
update ttt set count=@count-1
commit TRAN
SELECT * FROM ttt
ڣͬһʱȡƱΪ300ÿƱ㶼һθΪ299IJƱ1ʵʳƱ
ѯڣֱϴ뼴ɿЧ
ͣ
ŲǾֵģÿһ̶߳ҪﵽĿĵġ
ֹŲǼģˣͷϢٴγԡΪǼġ
1
2
3
4
5
6
7
declare @count as int
begin tran
select @count=count from tb WITH(UPDLOCK)
WAITFOR DELAY '00:00:05' --ģⲢӳ5
update tb set count=@count-1
commit tran
ڲѯʱһ֤Բѯֱᱻȡģݡ
ӶԽ⡣
ֹ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
--ȸһtimestamp
ALTER TABLE ttt ADD timesFlag TIMESTAMP NOT null
ȻʱжֵǷ
declare @count as int
DECLARE @flag AS TIMESTAMP
DECLARE @rowCount AS int
begin tran
select @count=COUNT,@flag=timesflag from ttt
WAITFOR DELAY '00:00:05'
update ttt set count=@count-1 WHERE timesflag=@flag --
SET @rowcount=@@ROWCOUNT --ȡĵ
commit TRAN
--жϼ
IF @rowCount=1
PRINT '³ɹ'
ELSE
PRINT 'ʧ'
ֹĽԽݴ⣬֤ÿһεø¶ɹܻ᷵'ʧ'
ֹ
һɹڲرʱɺܳʱʺС
ֹһÿζijɹܳϵͳIJƣڴʱЧҪߺܶࡣ