insert into与insert ignore以及replace into的区别
insert ignore表示,如果表中已经存在相同的记录,则忽略当前新数据;
INSERT INTO有无数据都插入,如果主键则不插入;
REPLACE INTO 如果是主键插入则会替换以前的数据;
例
1.insert语句一次可以插入多组值,每组值用一对圆括号括起来,用逗号分隔,如下:
insert into `news`(title,body,time) values('www.111cn.net','body 1',now()),('title 2','body 2',now());
下面通过代码说明之间的区别,如下:
create table testtb(
id int not null primary key,
name varchar(50),
age int
);
insert into testtb(id,name,age)values(1,"www.111Cn.net",13);
select * from testtb;
insert ignore into testtb(id,name,age)values(1,"aa",13);
select * from testtb;//仍是1,“bb”,13,因为id是主键,出现主键重复但使用了ignore则错误被忽略
replace into testtb(id,name,age)values(1,"aa",12);
select * from testtb; //数据变为1,"aa",12
insert into与insert ignore以及replace into的区别的更多相关文章
- MySQL中的insert ignore into, replace into等的一些用法小结(转)
MySQL中的insert ignore into, replace into等的一些用法总结(转) 在MySQL中进行条件插入数据时,可能会用到以下语句,现小结一下.我们先建一个简单的表来作为测试: ...
- MySQL的insert ignore与replace into不同
以前从来没有接触过replace into这个语法,但是却看到很多人都在使用这个语法,并且应用在很多生产环境中,于是我也去学习了一下repalce into的用法. 关于replace 一句话:正常情 ...
- MySQL数据库INSERT、UPDATE、DELETE以及REPLACE语句的用法详解
本篇文章是对MySQL数据库INSERT.UPDATE.DELETE以及REPLACE语句的用法进行了详细的分析介绍,需要的朋友参考下 MySQL数据库insert和update语句引:用于操作数 ...
- 转载:MySQL数据库INSERT、UPDATE、DELETE以及REPLACE语句的用法详解
转自:http://www.jb51.net/article/39199.htm 本篇文章是对MySQL数据库INSERT.UPDATE.DELETE以及REPLACE语句的用法进行了详细的分析介绍, ...
- SQLiteDatabase执行update、insert操作的时候,conflictAlgorithm参数的含义区别
/** * When a constraint violation occurs, an immediate ROLLBACK occurs, * thus ending the current tr ...
- (转)oracle触发器使用:after insert 与before insert的简单使用注意
本文转载自:http://blog.csdn.net/kuangfengbuyi/article/details/41446125 创建触发器时,触发器类型为after insert , 在begin ...
- 关于insert /*+ append*/ 各种insert插入速度比较
来源于:http://www.cnblogs.com/rootq/archive/2009/02/11/1388043.html SQL> select count(*) from t;COUN ...
- Oracle 的 INSERT ALL和INSERT FIRST
描述性的东西就不来了,搞技术的,最喜欢实在的实例.通过下面的例子,大家很快就能明白insert all 与 insert first 的功能,比文字描述更通俗易懂. 一.INSERT ALL 不带条件 ...
- insert /*+APPEND*/ 各种insert 插入速度比较
SQL> select count(*) from t;COUNT(*)----------5442048****************************SQL> alter ta ...
随机推荐
- LeetCode 141. Linked List Cycle环形链表 (C++)
题目: Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked ...
- About The Algorithm Simplification
For mode 1, you have to ergod all the data in the files. So the key point to solve this problem is t ...
- 我是一个程序猿 ——《不是书评 :<我是一只IT小小鸟>》有感
读了刘未鹏先生的文章<不是书评 :<我是一只IT小小鸟>>,产生了诸多共鸣,更明白了不少道理. 首先是一个很平常的现象,进度条效应,在操作移动终端上的软件时,如果没有进度条,人 ...
- 11th 最后的致意
“终于我们不再是师生”,无论日后我们是否是师生,但这段经历是不可否认的,可以说软件工程这一门课程恐怕是我学生生涯中终生难忘的一段体验.即便不是从知识上,从另一个方面来讲,也教给了我一种做人做事的态度. ...
- Linux下搭建testlink1.9.17
如果只是要搭建testlink服务的话,建议使用testlink的集成安装包,能避免很多坑 下载地址:https://bitnami.com/stack/testlink/installer 下载好后 ...
- [转帖]Prometheus+Grafana监控Kubernetes
原博客的位置: https://blog.csdn.net/shenhonglei1234/article/details/80503353 感谢原作者 这里记录一下自己试验过程中遇到的问题: . 自 ...
- MySQL基础(二):视图、触发器、函数、事务、存储过程
一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用. 视图和上一篇学到的临时表搜索类似. ...
- Duplicate spring bean id
问题背景:从本地调用服务器的dubbo接口进行测试 实现思路:基于IDEA+Spring+maven+Dubbo搭建测试项目,从本地直接调用 具体实现思路可参考博客:https://www.cnb ...
- ubuntu关闭和开启防火墙
1.关闭ubuntu的防火墙 ufw disable 2开启防火墙 ufw enable 3.卸载了iptables apt-get remove iptables 4.关闭ubuntu中的防火墙的其 ...
- 51nod 1494 选举拉票 (线段树+扫描线)
1494 选举拉票 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 现在你要竞选一个县的县长.你去对每一个选民进 ...