首页 >后端开发 >php教程 >mysql怎么同时更新2个表

mysql怎么同时更新2个表

WBOY
WBOY原创
2016-06-06 20:49:161400浏览

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

回复内容:

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

<code>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)
</code>

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

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn