主キーがなければINSERTしてあればUPDATE - INSERT ON DUPLICATE KEY UPDATECREATE TABLE t1 ( id1 int UNIQUE, id2 int); INSERT INTO t1 ( id1, id2 ) VALUES ( 1, 100 ) ON DUPLICATE KEY UPDATE id2 = id2 + 1; +------+------+ | id1 | id2 | +------+------+ | 1 | 100 | +------+------+ INSERT INTO t1 ( id1, id2 ) VALUES ( 1, 100 ) ON DUPLICATE KEY UPDATE id2 = id2 + 1; +------+------+ | id1 | id2 | +------+------+ | 1 | 101 | +------+------+ 参考https://stackoverflow.com/questions/6030071/mysql-table-insert-if-not-exist-otherwise-update |
|