当前位置:网站首页>解决MySQL主键id从1开始自增 ,id不连续的问题
解决MySQL主键id从1开始自增 ,id不连续的问题
2022-07-20 23:38:00 【梦远星帆】
alter table tablename auto_increment = 1;
这个命令不会改动现有的表的内容和顺序,同时新插入行的id会先使用已删除的id,完美填补空缺id。
但这样按id排序就不一定是id大的写入时间晚了。
对于表格内某些行删除之后,id不连续这个问题完全无法容忍,一开始使用TRUNCATE TABLE tablename
来实现id从头自增,但是这个命令同时也会清空整个表 。
不连续
是因为mysql AUTO_INCREMENT有预分配,先申请,后使用,申请了没使用就跳了, 比如inser ignore 语句,因为有插入语句,所以一开始mysql就会给分配一个自增id,即便你没执行插入成功语句,下次再插入的时候就会调健
边栏推荐
- Huawei wireless device WLAN QoS configuration command
- How to analyze and design performance test scenarios
- 【精选】Mysql B-Tree和B+Tree的结构?
- C#(三十三)之路径(Path)
- Chapter V central processing unit
- Ora-01461: only the long value to be inserted into the long column can be bound
- 【等保常见问题解答】等保测评机构能帮忙做等保整改吗?
- Codeforces Round #809 (Div. 2)
- 中国高校江湖绰号
- 成为比开发更硬气的测试人,我都经历了什么?
猜你喜欢
音视频开发进阶|第四讲:音频自动增益控制 AGC
Jmeter-正则、xpath、JSON
【测试开发】软件测试——测试用例设计&测试分类详解
C (37) FileStream
YOLOv7实验测试之一:遥感图像检测应用
How to analyze and design performance test scenarios
[基础架构] [Flink] Flink/Flink-CDC代码实现业务接入
线程间有哪些资源是不可以共享的?
如何提取Matlab可视化图像窗口Figure中的坐标信息
JS syntax variables (declaration, naming conventions, declaration of multiple variables at one time, use)
随机推荐
Path of C (33)
浅聊一波moveit2
YOLOv5改进之二:添加CBAM注意力机制
C#(四十三)之线程Mutex互斥
IP第十一天笔记
ICML 2022 | 教程效度,可靠性和意义:可复现机器学习的统计方法教程
Time series analysis of port berths during Arima epidemic
Three sequence traversal BFs of binary tree
新鲜出炉的 yoloV5可视化实战项目(1)
IP day 11 notes
[featured] the structure of MySQL B-tree and b+tree?
Opencv learning - aruco module
What resources cannot be shared between threads?
Niagara - UE5中的粒子系统
C#(四十一)之线程
第五章 中央处理器
Coordinate transformation of C (34)
【等保常见问题解答】等保测评机构能帮忙做等保整改吗?
235. 二叉搜索树的最近公共祖先-dfs法
C#(三十九)之关于string的一些函数