当前位置:网站首页>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
边栏推荐
- Openwrt directory structure
- rtklib2.4.3 b34 单点定位的一个bug
- MySQL存储过程
- Cloud function realizes fuzzy search function
- 入行软件测试5年,跳槽3次,我摸透了软件测试这一行
- Left and right values
- 《微信小程序-基础篇》带你了解小程序的路由系统(二)
- JDBC调用存储过程、MySQL触发器
- Flask Foundation: environment setup + configuration + mapping between URL and attempt + redirection + database connection
- Actual combat | multiple intranet penetration through Viper
猜你喜欢

【Mac】安全性与隐私中没有任何来源选项

TabControl style of WPF basic control

微信小程序:星际旅行飞船乘坐票制作生成

MVC三层架构

"Wechat applet - Basics" takes you to understand the routing system of the applet (2)

Official download and installation of QT and QT vs tools plug-ins

Abnova actn4 purified rabbit polyclonal antibody instructions

《微信小程序-基础篇》带你了解小程序的路由系统(二)

What are the types of independent station chat robots? How to quickly create your own free chat robot? It only takes 3 seconds!

With the arrival of intelligent voice era, who is defining AI in the new era?
随机推荐
Amazing tips for using live chat to drive business sales
Thinkphp6 linked table query without associated ID (2 tables) is mainly the application of select
Do280openshift command and troubleshooting -- common troubleshooting and chapter experiments
【Mac】安全性与隐私中没有任何来源选项
Li Kou today's question 513 Find the value in the lower left corner of the tree
dolphinscheduler 2.0.5 spark 任务测试总结(源码优化)
Usage of apipost interface test ------ get
rtklib2.4.3 b34 单点定位的一个bug
WPF 基础控件之 TabControl样式
【毕业季_进击的技术er】送别过去两年迷茫的自己。重整旗鼓,大三我来啦
Pads and flash symbols in cadence
How to use data to tell a wonderful story?
《微信小程序-基础篇》带你了解小程序的路由系统(二)
Reinstallation of cadence16.3, failure and success
395. redundant path
轮播图的实现
Thesis reading_ Relation extraction_ CASREL
ZK has a node reporting it is possible not running and the log has no obvious error
The solution to prompt "this list creation could be rewritten as a list literal" when adding elements to the list using the append() method in pychart
Shadertoy basic teaching 01. Circle drawing (explanation of smoothstep() function)