返回顶部

收藏

mysql INSERT ON DUPLICATE KEY UPDATE示例

更多
mysql>
mysql>
mysql>
mysql> CREATE   TABLE TEAMS
    ->         (TEAMNO         INTEGER      NOT NULL,
    ->          EmployeeNO       INTEGER      NOT NULL,
    ->          DIVISION       CHAR(6)      NOT NULL,
    ->          PRIMARY KEY    (TEAMNO)             );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> INSERT INTO TEAMS VALUES (1,  6, 'first');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO TEAMS VALUES (2, 27, 'second');
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> INSERT INTO TEAMS VALUES (1, 39, 'second')
    -> ON DUPLICATE KEY UPDATE EmployeeNO = 39, DIVISION='second';
Query OK, 2 rows affected (0.00 sec)

mysql>
mysql> drop table teams;
Query OK, 0 rows affected (0.00 sec)

mysql>

标签:mysql,sql

收藏

0人收藏

支持

0

反对

0

评论

  • INSERT INTO TEAMS VALUES (1, 39, 'second') -> ON DUPLICATE KEY UPDATE EmployeeNO = 39, DIVISION='second'; 这个UPDATE后面的是更新条件吗?? 为什么我弄的一直在新增 重复了还可以新增??

    回复   |   你如星星一般难觅? 发表于 2017-06-01 14:17:36