当前位置:网站首页>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
边栏推荐
- Clang Code Model: Error: The clangbackend executable “X:/clangbackend.exe“ could not be started
- 什么是机器强化学习?原理是什么?
- Detailed explanation of VIT source code
- C language recv() function, recvfrom() function, recvmsg() function
- .NET service registration
- 【人话版】WEB3将至之“权益的游戏”
- Callable实现多线程
- LeetCode814 Math Question Day 15 Binary Tree Series Value "814 Binary Tree Pruning"
- En-us is an invalid culture error solution when Docker links sqlserver
- 直播平台开发,Flutter,Drawer侧滑
猜你喜欢
【FPGA】day21- moving average filter
Provincial level of Echart maps, as well as all prefecture-level download and use
What is ensemble learning in machine learning?
Which one to choose for mobile map development?
"104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series
【FPGA】day22-SPI protocol loopback
移动端地图开发选择哪家?
LeetCode814算题第15天二叉树系列值《814 二叉树剪枝》
console.log alternatives you didn't know about
Detailed explanation of VIT source code
随机推荐
.NET service registration
Interchangeability Measurements and Techniques - Calculation of Deviations and Tolerances, Drawing of Tolerance Charts, Selection of Fits and Tolerance Classes
校园兼职平台项目反思
The last update time of the tables queried by the two nodes of the rac standby database is inconsistent
直播软件搭建,流式布局,支持单选、多选等
洛谷P1196 银河英雄传说
机器学习中什么是集成学习?
Basic understanding of MongoDB (2)
How to rebuild after pathman_config and pathman_config_params are deleted?
"125 Palindrome Verification" of the 10th day string series of LeetCode brushing questions
【FPGA】day22-SPI协议回环
电力机柜数据监测RTU
MYSQLg高级------聚簇索引和非聚簇索引
我的 archinstall 使用手册
【FPGA】名词缩写
[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface
WPF DataGrid 使用数据模板(2)
"104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series
Uni - app - access to Chinese characters, pinyin initials (according to the Chinese get pinyin initials)
拼多多店铺营业执照相关问题