当前位置:网站首页>数据库表中不建索引,在插入数据时,通过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
边栏推荐
- PID debugging of coding motor (speed loop | position loop | follow)
- Mysql database
- 中后二叉建树
- Top ten project management software similar to JIRA
- 可以接收多種數據類型參數——可變參數
- 12. < tag linked list and common test site synthesis > - lt.234 palindrome linked list
- C language to achieve address book - (static version)
- Tips in MATLAB
- [authentication / authorization] customize an authentication handler
- 再战leetcode (290.单词规律)
猜你喜欢
2022T电梯修理考试模拟100题及在线模拟考试
After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
The most understandable life cycle of dependency injection
The most easy to understand dependency injection and control inversion
荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比
[new version release] componentone added Net 6 and blazor platform control support
Drawing polygons with < polygon / > circular array in SVG tag
Eight elder brothers chronicle [4]
Fight leetcode again (290. Word law)
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
随机推荐
OLED multi-level menu record
[Mysql] LEFT函數 | RIGHT函數
准备一个月去参加ACM,是一种什么体验?
Use of slice grammar sugar in C #
Blazor University (11) component - replace attributes of subcomponents
svg标签中利用<polygon/>循环数组绘制多边形
Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
手机连接电脑后,QT的QDIR怎么读取手机文件路径
再战leetcode (290.单词规律)
Judge whether there is a leap year in the given year
全网最全,接口自动化测试怎么做的?精通接口自动化测试详解
LoadRunner - performance testing tool
Iotos IOT middle platform is connected to the access control system of isecure center
2022A特种设备相关管理(电梯)上岗证题库及模拟考试
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
一套组合拳,打造一款 IDEA 护眼方案
Student achievement management
Experiment 6 input / output stream
使用DFS来解决“字典序排数”问题
How does Microsoft solve the problem of multiple programs on PC side -- internal implementation