当前位置:网站首页>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
边栏推荐
猜你喜欢
机器学习可以应用在哪些场景?机器学习有什么用?
【FPGA】设计思路——I2C协议
Basic understanding of MongoDB (2)
【深度学习】基于卷积神经网络的天气识别训练
Get Qt installation information: including installation directory and various macro addresses
快速使用UE4制作”大场景游戏“
[C Language] Getting Started
Provincial level of Echart maps, as well as all prefecture-level download and use
es-head插件插入查询以及条件查询(五)
Echart地图的省级,以及所有地市级下载与使用
随机推荐
Get the length of the linked list
二叉堆的基础~
(转)JVM中那些区域会发生OOM?
洛谷P4061 大吉大利,晚上吃鸡
leetcode刷题第13天二叉树系列之《98 BST及其验证》
使用jackson解析json数据详讲
Redis:解决分布式高并发修改同一个Key的问题
Read the article, high-performance and predictable data center network
【人话版】WEB3将至之“权益的游戏”
LeetCode814 Math Question Day 15 Binary Tree Series Value "814 Binary Tree Pruning"
What is machine learning?Explain machine learning concepts in detail
无线电射频能量的收集
"104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series
leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》
洛谷P2580 于是他错误的点名开始了
[Likou] 22. Bracket generation
[C Language] Getting Started
"239 Sliding Window Maximum Value" on the 16th day of LeetCode brushing
【服务器安装Redis】Centos7离线安装redis
Map中的getOrDefualt方法