当前位置:网站首页>Mysql: set the primary key to automatically increase the starting value
Mysql: set the primary key to automatically increase the starting value
2022-08-11 04:26:00 【A rookie is a great god】
Achievement goal: The value of the self-incrementing primary key under mysql will start from 10000, that is, the seed for realizing the self-incrementing primary key is 10000.
Option 1) Use alter table `tablename` AUTO_INCREMENT=10000
After creating the auto-incrementing primary key, use alter table `tablename` AUTO_INCREMENT=10000 to modify the starting value of the table.

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 name10000 name2
Scenario 2) Set the AUTO_INCREMENT 10000 parameter when creating a table
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 name10000 name2
3) If the table already has data, set auto_increment=10000 after truncate, which is feasible.
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 name10000 names
Result2:
id name10000 name2
4) If the table already has data, set auto_increment=10000 after delete from, which is feasible.
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 name10000 names
Result2:
id name10000 name2
边栏推荐
- How to add icons to web pages?
- LeetCode Brush Questions Day 11 String Series "58 Last Word Length"
- es-head plugin insert query and conditional query (5)
- 使用jackson解析json数据详讲
- "98 BST and Its Verification" of the 13th day of leetcode brushing series of binary tree series
- MYSQLg advanced ------ clustered and non-clustered indexes
- 直播软件搭建,流式布局,支持单选、多选等
- How to delete statements audit log?
- [FPGA] day19- binary to decimal (BCD code)
- "239 Sliding Window Maximum Value" on the 16th day of LeetCode brushing
猜你喜欢

【力扣】22.括号生成

Which one to choose for mobile map development?

The custom of the C language types -- -- -- -- -- - structure

【人话版】WEB3将至之“权益的游戏”

Graphical LeetCode - 640. Solving Equations (Difficulty: Moderate)

「转」“搜索”的原理,架构,实现,实践,面试不用再怕了

CTO said that the number of rows in a MySQL table should not exceed 2000w, why?

机器学习怎么学?机器学习流程

【FPGA】day21-移动平均滤波器

【FPGA】SDRAM
随机推荐
Graphical LeetCode - 640. Solving Equations (Difficulty: Moderate)
直播平台开发,Flutter,Drawer侧滑
获取Qt的安装信息:包括安装目录及各种宏地址
What are port 80 and port 443?What's the difference?
【FPGA】SDRAM
Mysql中事件和定时任务
洛谷P4032 火锅盛宴
[FPGA] day19- binary to decimal (BCD code)
[Likou] 22. Bracket generation
"239 Sliding Window Maximum Value" on the 16th day of LeetCode brushing
jwsManager服务接口实现类-jni实现
洛谷P2150 寿司晚宴
es-head plugin insert query and conditional query (5)
洛谷P1196 银河英雄传说
【深度学习】基于卷积神经网络的天气识别训练
Introduction to c # a week of high-level programming c # - LINQ Day Four
Enter the starting position, the ending position intercepts the linked list
优先级队列
拼多多店铺营业执照相关问题
Interchangeability and Measurement Techniques - Tolerance Principles and Selection Methods