存储过程里面怎么处理并发啊

 现在我的card表里的count为8 表示有8张卡  如果我有10个并发线程去调用  最后的结果是card表count为0  但是mycard表 会有10条记录 
就是10个人抢8张卡 结果10个人都抢到了


declare update_count int;
declare tmp_update_count int default 0;
declare t_error integer default 0;
declare temp int;
declare continue handler for SQLEXCEPTION set t_error = 1;
start transaction;
   update card set count = count-1 where count >= 1 and cardId = cardId;
   select row_count() into update_count;
   select sleep(1) into temp;
if update_count > 0 then 
   insert into myCard (UserId, ShopID, CardID, OrderID, R_Date, Score) values (userId, shopId, cardId, orderId, applyDate, score);
   select row_count() into tmp_update_count;
end if;


if t_error = 1 then 
   set tmp_update_count = 0;
   rollback;
else
    commit;
end if


select tmp_update_count as update_count;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值