我不明白为什么MySQL不允许在存储过程中进行表锁定。
我的存储过程中有以下SQL语句:
我的存储过程中有以下SQL语句:
-- Total amount of money for comments
start transaction;
select @num_comments := count(*)
from `comment` c
where
c.user_id = user_id and
c.payment_rejection = 'NO' and
c.is_recorded = 0;
update `user` u set account_balance += u.comment_price * @num_comments where u.user_id = user_id;
update `comment` c set is_recorded = 1 where c.user_id = user_id and c.payment_rejection = 'NO' and c.is_recorded = 0;
commit;
所以我必须锁定 comment
表,以防止任何写入操作,因为这可能会导致第一个 SQL 语句选中的行数与实际更新的行数不同。