当前位置:网站首页>关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法
关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法
2022-07-31 02:21:00 【长沙红胖子Qt】
若该文为原创文章,转载请注明原文出处
本文章博客地址:https://hpzwl.blog.csdn.net/article/details/126074729
红胖子(红模仿)的博文大全:开发技术集合(包含Qt实用技术、树莓派、三维、OpenCV、OpenGL、ffmpeg、OSG、单片机、软硬结合等等)持续更新中…
数据库相关开发
需求
配置文件存入有时候数据库没有初始化一条数据,所有想使用有数据就更新,没数据则插入的方式。
问题
在实际调试过程中,发现id为0时,每次replace表id为0的记录,都会使id自增,如下图:

表数据结构定义和操作




解决方式一:修改id值,id值不能为0
将存入的id值改为1,验证不能为0,为0则会自动自增添加新的一条数据。
解决方法二:修改表结构,id改为不自增


若该文为原创文章,转载请注明原文出处
本文章博客地址:https://hpzwl.blog.csdn.net/article/details/126074729
边栏推荐
猜你喜欢

Pythagorean tuple od js

【银行系列第一期】中国人民银行

Basic introduction to ShardingJDBC

19.支持向量机-优化目标和大间距直观理解

怎样做好一个创业公司CTO?

Difference between CMOS and TTL?

Can an inexperienced college graduate switch to software testing?my real case

CMOS和TTL的区别?

加密生活,Web3 项目合伙人的一天
![The comprehensive result of the case statement, do you know it?[Verilog Advanced Tutorial]](/img/8a/28427aa773e46740eda9e95f6669f2.png)
The comprehensive result of the case statement, do you know it?[Verilog Advanced Tutorial]
随机推荐
Static routing + PAT + static NAT (explanation + experiment)
怎样做好一个创业公司CTO?
Shell script to loop through values in log file to sum and calculate average, max and min
Software Testing Defect Reporting - Definition, Composition, Defect Lifecycle, Defect Tracking Post-Production Process, Defect Tracking Process, Purpose of Defect Tracking, Defect Management Tools
直播预告 | KDD2022博士论文奖冠亚军对话
Observer mode (1)
mmdetection训练一个模型相关命令
全流程调度——MySQL与Sqoop
Nacos
Inner monologue from a female test engineer...
C语言小程序 -- 常见经典练习题
Intranet Infiltration - Privilege Escalation
mysql index
医疗影像领域AI软件开发流程
mysql view
Manchester City confuses fans with smart scarf that detects emotions
Force buckled brush the stairs (7/30)
Drools基本介绍,入门案例,基本语法
基于opencv实现人脸检测
The real CTO is a technical person who understands products