欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

mysql怎么同时更新2个表

程序员文章站 2022-05-01 13:50:48
...
想同时更新2个表,2表uid相同,修改a表name和b表nice,怎么破

回复内容:

想同时更新2个表,2表uid相同,修改a表name和b表nice,怎么破

mysql> select * from aa;
+------+
| id   |
+------+
|    2 |
+------+
1 row in set (0.00 sec)

mysql> select * from bb;
+------+
| id   |
+------+
|    2 |
+------+
1 row in set (0.00 sec)

mysql> update aa,bb set aa.id=3, bb.id=3 where aa.id=bb.id;
Query OK, 2 rows affected (0.02 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> select * from bb;
+------+
| id   |
+------+
|    3 |
+------+
1 row in set (0.00 sec)

mysql> select * from aa;
+------+
| id   |
+------+
|    3 |
+------+
1 row in set (0.00 sec)

如果需要强制同步操作,可以使用事务

相关标签: mysql php