1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| mysql> create table test (nom int(1), etat int(1), pack int(1));
Query OK, 0 rows affected (0.06 sec)
mysql> alter table test add constraint uk_test unique key (nom, pack);
Query OK, 0 rows affected (0.19 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> insert into test values (1,2,1),(2,3,2);
Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into test (nom, etat, pack) values (1,3,2) on duplicate key update etat = values(etat);
Query OK, 1 row affected (0.03 sec)
mysql> select * from test;
+------+------+------+
| nom | etat | pack |
+------+------+------+
| 1 | 2 | 1 |
| 2 | 3 | 2 |
| 1 | 3 | 2 |
+------+------+------+
3 rows in set (0.00 sec)
mysql> insert into test (nom, etat, pack) values (1,3,1) on duplicate key update etat = values(etat);
Query OK, 2 rows affected (0.03 sec)
mysql> select * from test;
+------+------+------+
| nom | etat | pack |
+------+------+------+
| 1 | 3 | 1 |
| 2 | 3 | 2 |
| 1 | 3 | 2 |
+------+------+------+
3 rows in set (0.00 sec)
mysql> |
Partager