当前位置:网站首页>数据库表中不建索引,在插入数据时,通过sql语句防止重复添加(转载)
数据库表中不建索引,在插入数据时,通过sql语句防止重复添加(转载)
2022-04-23 03:15:00 【JavaTestZhangy】
INSERT IGNORE INTO table(aaa,bbb)
SELECT '1111','2222' FROM DUAL
WHERE NOT EXISTS(
SELECT id FROM table WHERE bbb= '2222'
)
mybaits
<insert id="addItemCharacteristic" parameterType="com.orderalliance.entity.CharacteristicDTO">
<!--INSERT INTO table (item_id,characteristic) VALUES(#{aaa,jdbcType=BIGINT},#{bbb,jdbcType=VARCHAR})-->
<!--此sql语句防止数据重复添加-->
INSERT IGNORE INTO table (aaa,bbb)
SELECT #{111,jdbcType=BIGINT},#{222,jdbcType=VARCHAR} FROM DUAL
WHERE NOT EXISTS(
SELECT id FROM table WHERE bbb= #{bbb,jdbcType=VARCHAR}
)
</insert>
关键代码
INSERT IGNORE INTO 表名('字段')
SELECT '字段需要插入时的数据' FROM dual
WHERE NOT EXISTS
(SELECT * FROM '表名' WHERE '需要被限制不重复的字段' = '被限制字段本次插入的数据')
关键词
IGNORE
NOT EXISTS
版权声明
本文为[JavaTestZhangy]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_23490959/article/details/90669128
边栏推荐
- Eight elder brothers chronicle [4]
- Knowledge of software testing~
- 搭建XAMPP时mysql端口被占用
- 可以接收多种数据类型参数——可变参数
- Find the number of leaf nodes of binary tree
- How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
- Recommend reading | share the trader's book list and ask famous experts for trading advice. The trading is wonderful
- 一套组合拳,打造一款 IDEA 护眼方案
- “如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
- ASP. Net and ASP NETCORE multi environment configuration comparison
猜你喜欢

2022g2 boiler stoker examination question bank and online simulation examination

Source generator actual combat

Yes Redis using distributed cache in NE6 webapi

数据挖掘系列(3)_Excel的数据挖掘插件_估计分析

LoadRunner - performance testing tool

. net tip: talk about the problem that the scoped service cannot be obtained in the middleware structure

Tencent video VIP member, weekly card special price of 9 yuan! Tencent official direct charging, members take effect immediately!

ASP. Net 6 middleware series - execution sequence

Xutils3 corrected a bug I reported. Happy

Due to 3 ²+ four ²= five ², Therefore, we call '3,4,5' as the number of Pythagorean shares, and find the array of all Pythagorean shares within n (including n).
随机推荐
After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
C# 读写二进制文件
[MySQL] left function | right function
Judge whether there is a leap year in the given year
ASP. Net 6 middleware series - Custom middleware classes
Blazor University (11)组件 — 替换子组件的属性
Mysql database design specification
一文了解全面静态代码分析
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
2022年做跨境电商五大技巧小分享
C语言实现通讯录----(静态版本)
Tencent video VIP member, weekly card special price of 9 yuan! Tencent official direct charging, members take effect immediately!
Miniapi of. Net7 (special section): NET7 Preview3
Using positive and negative traversal to solve the problem of "the shortest distance of characters"
yes. Net future
准备一个月去参加ACM,是一种什么体验?
Xamarin effect Chapter 21 expandable floating operation button in GIS
Top 9 task management system in 2022
ASP. Net and ASP NETCORE multi environment configuration comparison
General test technology [II] test method