当前位置:网站首页>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
边栏推荐
- 【FPGA】day22-SPI protocol loopback
- 云平台下ESB产品开发步骤说明
- The development of the massage chair control panel makes the massage chair simple and intelligent
- Differences and connections between distributed and clustered
- What is third-party payment?
- The FTP error code list
- 移动端地图开发选择哪家?
- Get the length of the linked list
- En-us is an invalid culture error solution when Docker links sqlserver
- The thirteenth day of learning programming
猜你喜欢

leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》

Description of ESB product development steps under cloud platform
![[Likou] 22. Bracket generation](/img/f6/435fe9e0b4c1545514d1bf195ffd44.png)
[Likou] 22. Bracket generation

机器学习是什么?详解机器学习概念

Detailed explanation of VIT source code

Design and Realization of Employment Management System in Colleges and Universities

LeetCode刷题第17天之《3 无重复字符的最长子串》

Get Qt installation information: including installation directory and various macro addresses

STC8H development (15): GPIO drive Ci24R1 wireless module

Use jackson to parse json data in detail
随机推荐
洛谷P7441 Erinnerung
MYSQLg advanced ------ clustered and non-clustered indexes
我的 archinstall 使用手册
阿里云发布3大高性能计算解决方案
【深度学习】基于卷积神经网络的天气识别训练
一文读懂 高性能可预期数据中心网络
2022-08-10 The sixth group Hiding spring study notes
Use jackson to parse json data in detail
LeetCode814算题第15天二叉树系列值《814 二叉树剪枝》
【FPGA】day22-SPI protocol loopback
Design and Realization of Employment Management System in Colleges and Universities
Basic understanding of MongoDB (2)
常见布局效果实现方案
STC8H development (15): GPIO drive Ci24R1 wireless module
[FPGA] Design Ideas - I2C Protocol
leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》
A simple JVM tuning, learn to write it on your resume
CTO said that the number of rows in a MySQL table should not exceed 2000w, why?
这些云自动化测试工具值得拥有
电力机柜数据监测RTU