尝试insert ignore into
来源:互联网 发布:网络播放系统 编辑:程序博客网 时间:2024/06/06 03:08
对于主键冲突的时候,自动忽略当前要插入的记录。违反唯一性约束的时候,同样丢弃当前要插入的数据。
可以用在数据同步的场景,这个场景数据源只有insert 的Action,如果数据源含有update就会失败,不能同步update的更新字段。这样做到最终一直和幂等。
mysql> select * from test_table;+----+------+| id | kk |+----+------+| 1 | 1 || 3 | 2 || 4 | 3 || 6 | 5 |+----+------+4 rows in set (0.01 sec)mysql> show create table test_table;+------------+---------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+------------+---------------------------------------------------------------------------------------------------------------------------------------+| test_table | CREATE TABLE `test_table` ( `id` int(50) NOT NULL AUTO_INCREMENT, `kk` varchar(30) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `kk_uq` (`kk`)) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 |+------------+---------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)mysql> insert ignore into test_table(id, kk) values(6,7);Query OK, 0 rows affected (0.01 sec)mysql> insert ignore into test_table(id, kk) values(6,5);Query OK, 0 rows affected (0.00 sec)mysql> insert ignore into test_table(id, kk) values(5,5);Query OK, 0 rows affected (0.01 sec)mysql> insert ignore into test_table(id, kk) values(5,4);Query OK, 1 row affected (0.02 sec)mysql> select * from test_table;+----+------+| id | kk |+----+------+| 1 | 1 || 3 | 2 || 4 | 3 || 5 | 4 || 6 | 5 |+----+------+5 rows in set (0.00 sec)
0 0
- 尝试insert ignore into
- INSERT IGNORE 与INSERT INTO的区别
- INSERT IGNORE 与INSERT INTO的区别
- INSERT IGNORE 与INSERT INTO的区别
- INSERT IGNORE 与INSERT INTO的区别
- INSERT IGNORE 与INSERT INTO的区别
- INSERT IGNORE 与INSERT INTO的区别
- INSERT IGNORE 与INSERT INTO的区别
- INSERT IGNORE 与INSERT INTO的区别
- mysql insert into & replace into & insert ignore into
- mysql insert into replace into insert ignore into 用法
- INSERT IGNORE 与INSERT INTO ,replace into 的区别
- mysql 中insert ignore into 使用ignore来忽略错误
- mysql 中insert ignore into 使用ignore来忽略错误
- MySQL中INSERT IGNORE INTO和REPLACE INTO的使用
- sql语句insert ignore into 和replace into区别
- mysql 排除重复记录 insert 使用INSERT IGNORE into
- INERT DELEYED、INSERT IGNORE replace into和insert区别
- gnuplot-cpp library使用记录
- firefox对于keycode兼容性
- Load/Store内存访问指令
- 完成端口详解【IOCP】
- C#中Math.Round四舍五入的用法详解,
- 尝试insert ignore into
- JMS入门:一、基本构件
- 苹果Mac OS X怎样调整Ctrl/Option/Cmd按键位置
- js获取当前日期
- 大型分布式系统架构中的“let it crash”思想
- HDU 4704 Sum(隔板+费马小定理)
- USB设备驱动开发-USB Gadget Driver(一)
- “用人荒”?IT企业的招人难?不妨换个思路
- 《软件架构设计》学习笔记--1--阅读感悟