MySQL多表更新示例
作者:佚名 
  多表更新是我們經(jīng)常需要用到的功能,下文就以示例的形式為您詳細介紹多表更新的實現(xiàn)方法,希望對您能夠有所幫助。
 MySQL多表更新應(yīng)該如何是實現(xiàn)呢?對于很多剛接觸MySQL數(shù)據(jù)庫的新人來說,都會有這樣的疑問,下面就為您介紹MySQL多表更新的方法,供您參考。
MySQL多表更新:
- update contact c, contactdroit cd
 - set c.user_name = '$username', c.nom = '$lastname', c.prenom = '$firstname', c.passcode = '$password', cd.droit_id = '$droitid'
 - where c.contact_id = '$id' and c.contact_id = cd.contact_id;
 
示例:
- mysql> create table one(id int(10), name varchar(20));
 - Query OK, 0 rows affected (0.03 sec)
 - mysql> create table two(id int(10), name varchar(20));
 - Query OK, 0 rows affected (0.05 sec)
 - mysql> insert one value(1, '1');
 - Query OK, 1 row affected (0.00 sec)
 - mysql> insert two value(22, '22');
 - Query OK, 1 row affected (1.02 sec)
 - mysql> update one o, two t set o.name='oo', t.name='tt';
 - Query OK, 2 rows affected (0.00 sec)
 - Rows matched: 2 Changed: 2 Warnings: 0
 - mysql> select * from one;
 - +------+------+
 - | id | name |
 - +------+------+
 - | 1 | oo |
 - +------+------+
 - 1 row in set (0.00 sec)
 - mysql> select * from two;
 - +------+------+
 - | id | name |
 - +------+------+
 - | 22 | tt |
 - +------+------+
 - 1 row in set (0.00 sec)
 
【編輯推薦】
責任編輯:段燃 
                    來源:
                    互聯(lián)網(wǎng)
 














 
 
 




 
 
 
 