Can mysql have multiple FOR UPDATE in one transaction?

mysql can different tables FOR UPDATE multiple times in one transaction?

Jun.09,2022

Yes, such as

SET AUTOCOMMIT=0; 
BEGIN WORK;

SELECT * FROM test.B where cid=1 for update;
SELECT * FROM test.A where cid=1 for update;

update test.B set did=10 where cid=1;
update test.A set did=30 where cid=1;

commit work;
Menu