当前位置:网站首页>insert into... where not exists插入避免重复的使用
insert into... where not exists插入避免重复的使用
2022-06-23 03:54:00 【Dead_Cicle】
插入时为了方便,更是为了安全(避免查询==0? insert 这种方式),我们使用where not exists
下面代码:
-- 创建测试表
create table testage(
id int not null,
age int );
-- 插入三条数据
insert into testage(id,age) values(1,22);
insert into testage(id,age) values(2,23);
insert into testage(id,age) values(3,24);
-- 这里插入一条
insert into testage(id,age)
select 4,25 from dual
where not exists(select count(1) from testage where age=25);
猜一下执行结果?

是的,显示执行成功0,为什么?
我们单独执行这条sql,结果如图:

0存在吗?是存在的。需要更换为此种写法:

因为在插入之前,age=25是不存在的,查询是null
边栏推荐
- Abnova acid phosphatase (wheat germ) instructions
- Course design C for freshmen -- clothing management system
- 2022-06-22:golang选择题,以下golang代码输出什么?A:3;B:1;C:4;D:编译失败。 package main import ( “fmt“ ) func mai
- 元数据管理Apache Atlas编译(内嵌式)部署及遇到各种错误记录
- 云原生数据库如荼如火,未来可期
- How to use data to tell a wonderful story?
- Abnova fluorescent dye 555-c3 maleimide scheme
- 精密星历介绍与使用
- Laravel 8.4 routing problem. At the end is the cross reference table on the left side of the editor, which can be understood by Xiaobai
- 1183. electricity
猜你喜欢

直接插入排序——【常见排序法(1/8)】

TabControl style of WPF basic control

Flask基础:环境搭建+配置+URL与试图之间的映射+重定向+数据库连接

Mini Homer——几百块钱也能搞到一台远距离图数传链路?

元数据管理Apache Atlas编译(内嵌式)部署及遇到各种错误记录

开发一年不到,来面试居然敢开口要20K,面完连8K都不想给~

985测试工程师被吊打,学历和经验到底谁更重要?

Metadata management Apache Atlas Compilation (embedded) deployment and various error records encountered

How to use data to tell a wonderful story?

Less than a year after development, I dared to ask for 20k in the interview, but I didn't even want to give 8K after the interview~
随机推荐
Apache atlas quick start
Metadata management Apache Atlas Compilation (embedded) deployment and various error records encountered
Dolphin scheduler 2.0.5 task test (spark task) reported an error: container exited with a non zero exit code 1
ICer技能01正则匹配
Seven year manong Road
centos7部署docker,安装mysql
单行或多行文本溢出,省略号代替
直接插入排序——【常见排序法(1/8)】
微信小程序;AI智能配音助手
centos7安装postgresql8.2.15及存储过程创建
1183. electricity
Chrome debugging tips
数据科学家是不是特有前途的职业?
超越芯片和AI,硬科技资本为什么越来越“硬核”?
JSP入门级笔记
Usage of API interface test ------ post
How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
ICer技能03Design Compile
This markdown artifact will be charged!
Actual combat | multiple intranet penetration through Viper