例如我怎么控制
begin tran
select @id=id from web_user where username='ll'
update web_t set holdcount=holdcount+100 where userid=@id
commit tran怎样能让用户同时触发时不会出现错误.例如两次同时请求,结果只加了100
begin tran
select @id=id from web_user where username='ll'
update web_t set holdcount=holdcount+100 where userid=@id
commit tran怎样能让用户同时触发时不会出现错误.例如两次同时请求,结果只加了100
如何做到更新结束之前,锁定username='ll'的数剧,我用行锁好象没什么效果..
begin tran
select @holdcount=holdcount from web_user where username='ll'
if(@holdcount>100)
update web_user set holdcount =holdcount -100 where username='ll'
commit tran
--使用排它锁
begin tran
select @holdcount=holdcount from web_user with (paglock,xlock) where username='ll'
if(@holdcount>100)
update web_user set holdcount =holdcount -100 where username='ll'
commit tran --2使用REPEATABLEREAD锁,也可保证不会重复,但可能会死锁
begin tran
select @holdcount=holdcount from web_user with (repeatableread) where username='ll'
if(@holdcount>100)
update web_user set holdcount =holdcount -100 where username='ll'
commit tran --3使用SET TRANSACTION ISOLATION LEVEL REPEATABLE READ 情况与2相同
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
begin tran
select @holdcount=holdcount from web_user where username='ll'
if(@holdcount>100)
update web_user set holdcount =holdcount -100 where username='ll'
commit tran
update web_user set holdcount=holdcount where 1=2 and username='ll'
select @holdcount=holdcount from web_user where username='ll'
if(@holdcount>100)
update web_user set holdcount =holdcount -100 where username='ll'
commit tran
begin tran
update web_user set holdcount=holdcount where username='ll'
select @holdcount=holdcount from web_user where username='ll'
if(@holdcount>100)
update web_user set holdcount =holdcount -100 where username='ll'
commit tran
select @id=id ,@holdcount = holdcount from web_user with (rowlock) where username='ll'
update web_t set holdcount=holdcount+100 where userid=@id and and holdcount = ,@holdcount
commit tran
select @id=id ,@holdcount = holdcount from web_user with (rowlock) where username='ll'
update web_t set holdcount=holdcount+100 where userid=@id and and holdcount = ,@holdcount
commit tran