当前位置:网站首页>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
边栏推荐
- 增加PRODUCT_BOOT_JARS及类 提供jar包给应用
- Callable实现多线程
- 【深度学习】基于卷积神经网络的天气识别训练
- Multi-serial port RS485 industrial gateway BL110
- 机器学习中什么是集成学习?
- Introduction to c # a week of high-level programming c # - LINQ Day Four
- .NET service registration
- 【FPGA】day20-I2C读写EEPROM
- Provincial level of Echart maps, as well as all prefecture-level download and use
- 【服务器安装mysql】centos7下使用mysql离线安装包安装mysql5.7
猜你喜欢
【组成原理 九 CPU】
Provincial level of Echart maps, as well as all prefecture-level download and use
Read the article, high-performance and predictable data center network
北湖区燕泉街道开展“戴头盔·保安全”送头盔活动
How to learn machine learning?machine learning process
Which one to choose for mobile map development?
【FPGA】day21- moving average filter
一文读懂 高性能可预期数据中心网络
[Likou] 22. Bracket generation
【FPGA】abbreviation
随机推荐
Self-research capability was recognized again, and Tencent Cloud Database was included in the Forrester Translytical report
How to learn machine learning?machine learning process
洛谷P4061 大吉大利,晚上吃鸡
Binary tree related code questions [more complete] C language
How to add icons to web pages?
"125 Palindrome Verification" of the 10th day string series of LeetCode brushing questions
机器学习是什么?详解机器学习概念
洛谷P1763 埃及分数
二叉堆的基础~
C# 一周入门高级编程之《C#-LINQ》Day Four
[C Language] Getting Started
LeetCode刷题第10天字符串系列之《125回文串验证》
【FPGA】day22-SPI协议回环
「转」“搜索”的原理,架构,实现,实践,面试不用再怕了
直播平台开发,Flutter,Drawer侧滑
Alibaba Cloud releases 3 high-performance computing solutions
自研能力再获认可,腾讯云数据库入选 Forrester Translytical 报告
jwsManager服务接口实现类-jni实现
CTO said that the number of rows in a MySQL table should not exceed 2000w, why?
干货:服务器网卡组技术原理与实践