当前位置:网站首页>数据库表中不建索引,在插入数据时,通过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
边栏推荐
- Middle and rear binary tree
- TP5 inherits base and uses the variables in base
- 再战leetcode (290.单词规律)
- 手机连接电脑后,QT的QDIR怎么读取手机文件路径
- [mock data] fastmock dynamically returns the mock content according to the incoming parameters
- 2022g2 boiler stoker examination question bank and online simulation examination
- Laravel new route file
- Course design of Database Principle -- material distribution management system
- 2022 P cylinder filling training test questions and simulation test
- be based on. NETCORE development blog project starblog - (2) environment preparation and creation project
猜你喜欢

ASP. Net 6 middleware series - Custom middleware classes

Course design of Database Principle -- material distribution management system

二进制文件版本控制工具选择难?看完这篇你会找到答案
![[vs Code] solve the problem that the jupyter file displays exceptions in vs code](/img/f6/a91d03fd140eb5f7688b72e2e6f2bb.png)
[vs Code] solve the problem that the jupyter file displays exceptions in vs code

Blazor University (11) component - replace attributes of subcomponents

2022年P气瓶充装培训试题及模拟考试
![[new version release] componentone added Net 6 and blazor platform control support](/img/08/71e7328f685a5cdd584f1bfdce5f2a.png)
[new version release] componentone added Net 6 and blazor platform control support

ASP. Net 6 middleware series - execution sequence

搭建XAMPP时mysql端口被占用

软件测试相关知识~
随机推荐
Use DFS to solve the problem of "number of dictionary rows"
可以接收多種數據類型參數——可變參數
C read / write binary file
Swap the left and right of each node in a binary tree
宁德时代地位不保?
手机连接电脑后,QT的QDIR怎么读取手机文件路径
[Mysql] LEFT函数 | RIGHT函数
Mysql database
《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
Top ten project management software similar to JIRA
ASP. Net 6 middleware series - Custom middleware classes
使用栈来解决”迷你语法分析器“的问题
This new feature of C 11, I would like to call it the strongest!
2022A特种设备相关管理(电梯)上岗证题库及模拟考试
The most understandable life cycle of dependency injection
Drawing polygons with < polygon / > circular array in SVG tag
OLED多级菜单记录
Flink实时数仓项目—DWS层设计与实现
[MySQL] left function | right function
搭建XAMPP时mysql端口被占用