当前位置:网站首页>Mysql:设置主键自动增长起始值
Mysql:设置主键自动增长起始值
2022-08-11 04:00:00 【菜鸟是大神】
实现目标:mysql下将自增主键的值,从10000开始,即实现自增主键的种子为10000。
方案1)使用alter table `tablename` AUTO_INCREMENT=10000
创建自增主键之后,使用alter table `tablename` AUTO_INCREMENT=10000实现修改表起始值。
drop table if exists `trace_test`; CREATE TABLE `trace_test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; alter table `trace_test` AUTO_INCREMENT=10000; insert into `trace_test`(`name`)values('name2'); select * from `trace_test`;
Result:
id name 10000 name2
方案2)创建表时设置AUTO_INCREMENT 10000参数
drop table if exists `trace_test`; CREATE TABLE `trace_test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT 10000 DEFAULT CHARSET=utf8 ; insert into `trace_test`(`name`)values('name2'); select * from `trace_test`;
Result:
id name 10000 name2
3)如果表已有数据,truncate 之后设置auto_increment=10000,可行。
drop table if exists `trace_test`; CREATE TABLE `trace_test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; insert into `trace_test`(`name`)values('name1'); select * from `trace_test`; truncate table `trace_test`; alter table `trace_test` AUTO_INCREMENT=10000; insert into `trace_test`(`name`)values('name2'); select * from `trace_test`;
Result1:
id name 10000 name
Result2:
id name 10000 name2
4)如果表已有数据,delete from之后设置auto_increment=10000,可行。
drop table if exists trace_test; CREATE TABLE trace_test ( id int(20) NOT NULL AUTO_INCREMENT, name varchar(255) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; insert into trace_test(name)values('name1'); select * from trace_test; delete from `trace_test`; alter table trace_test AUTO_INCREMENT=10000; insert into trace_test(name)values('name2'); select * from trace_test;
Result1:
id name 10000 name
Result2:
id name 10000 name2
边栏推荐
- 多串口RS485工业网关BL110
- 【Yugong Series】August 2022 Go Teaching Course 036-Type Assertion
- Build Zabbix Kubernetes cluster monitoring platform
- Detailed explanation of VIT source code
- C# 一周入门高级编程之《C#-LINQ》Day Four
- What problems should we pay attention to when building a programmatic trading system?
- Multi-serial port RS485 industrial gateway BL110
- js uses the string as the js execution code
- 获取Qt的安装信息:包括安装目录及各种宏地址
- MYSQLg advanced ------ return table
猜你喜欢
LeetCode刷题第12天二叉树系列之《104 二叉树的最大深度》
使用jackson解析json数据详讲
(转)JVM中那些区域会发生OOM?
[FPGA] day19- binary to decimal (BCD code)
Day20 FPGA 】 【 - block the I2C read and write EEPROM
What is machine learning?Explain machine learning concepts in detail
LeetCode814算题第15天二叉树系列值《814 二叉树剪枝》
leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》
Read the article, high-performance and predictable data center network
Qnet Weak Network Test Tool Operation Guide
随机推荐
【力扣】22.括号生成
使用百度EasyDL实现智能垃圾箱
Build Zabbix Kubernetes cluster monitoring platform
多串口RS485工业网关BL110
UNI-APP_iphone bottom safe area
When EasyCVR is connected to the GB28181 device, what is the reason that the device is connected normally but the video cannot be played?
洛谷P1763 埃及分数
拼多多店铺营业执照相关问题
2022-08-10 The sixth group Hiding spring study notes
Basic understanding of MongoDB (2)
Provincial level of Echart maps, as well as all prefecture-level download and use
常见布局效果实现方案
什么是机器强化学习?原理是什么?
What are port 80 and port 443?What's the difference?
Leetcode 108. 将有序数组转换为二叉搜索树
Detailed explanation of VIT source code
The thirteenth day of learning programming
App基本框架搭建丨日志管理 - KLog
C语言 recv()函数、recvfrom()函数、recvmsg()函数
一文读懂 高性能可预期数据中心网络