(mysql)update同时更新多个表

(1)同时更新的多个表之间没关系的:

update table1 t1,table2 t2 set t1.a=1,t2.b=2 where t1.id=1 and t2.id=1

(2)同时更新的多个表之间存在关系的:

use mytest; CREATE TABLE tb(id int ,data varchar(20)); insert tb values(1,'aaa'); insert tb values(2,'bbb'); insert tb values(3,'ccc'); use test; CREATE TABLE tb(id int ,data varchar(20)); insert tb values(1,'aaa'); insert tb values(2,'bbb'); insert tb values(3,'ccc'); UPDATE mytest.tb,test.tb SET mytest.tb.data='liangCK', test.tb.data='liangCK' WHERE mytest.tb.id=test.tb.id AND mytest.tb.id=2;