当前位置:网站首页>Talk about auto in MySQL in detail_ What is the function of increment
Talk about auto in MySQL in detail_ What is the function of increment
2022-06-29 22:40:00 【1024 Q】
Source of problem
explain
matters needing attention
summary
Source of problemA lot of times ,MySQL In the statement 【auto_increment】 This word , Most of the time , Tables are automatically generated , Just beginning to learn MySQL Database will learn , later , Gradually you may forget , What exactly does this sentence mean ? below , Let's summarize :
explainauto_increment It is used for automatic growth of primary keys , from 1 Start to grow , When you delete the first record , When you insert the second data , The primary key value is 2, No 1.
for example :
create table test(id int(10) not null auto_increment, – Indicates auto increment name varchar(20) not null,primary key(id))auto_increment = 1; – Indicates the starting size of self increment -- So you can create a table test,id For the column
– Execute statement insert into test (name) values (‘ name ’);
– You can insert a row of data as : 1 ‘ name ’
In the use of AUTO_INCREMENT when , We should pay attention to the following points :
1、AUTO_INCREMENT Is an attribute of a data column , Only applicable to integer type data columns .
2、 Set up AUTO_INCREMENT The data column of the attribute should be a sequence of positive numbers , Therefore, the data column should be declared as UNSIGNED, In this way, the number of sequences can be doubled .
3、AUTO_INCREMENT Data columns must have unique indexes , To avoid repetition of serial numbers ( That is, the primary key or part of the primary key ).
AUTO_INCREMENT The data column must have NOT NULL attribute .
4、AUTO_INCREMENT The maximum value of the serial number of a data column is constrained by the data type of the column , Such as TINYINT The maximum number of data columns is 127, If you add UNSIGNED, The maximum is 255. Once the ceiling is reached ,AUTO_INCREMENT It will fail. .
5、 When deleting all tables ,MySQL AUTO_INCREMENT From 1 Restart numbering .
This is because when performing a full table operation ,MySQL( and PHP The best combination ) In fact, this optimization operation is done : First delete all the data and indexes in the data table , Then rebuild the data table .
If you want to delete all data rows and keep the serial number information , You can use a belt like this where Of delete Command to suppress MySQL( and PHP The best combination ) The optimization of the :delete from table_name where 1;
You can use last_insert_id() Get the value that has just been self incremented .
explain : Part of the content comes from search and collation , The purpose is to record the summary , Learn to use ~
summaryThis is about MySQL in auto_increment What is the role of the article introduced here , More about MySQL in auto_increment Please search the previous articles of the software development network or continue to browse the relevant articles below. I hope you will support the software development network more in the future !
边栏推荐
- Grep tool
- Common PostgreSQL data operation notes: time
- MySQL lock common knowledge points & summary of interview questions
- Steady! The best posture for thousands of microservices to access Zadig (helm chart)
- 稳!上千微服务接入 Zadig 的最佳姿势(Helm Chart 篇)
- Free PDF to word software sharing, these software must know!
- static关键字续、继承、重写、多态
- Realizing deep learning framework from zero -- LSTM from theory to practice [theory]
- 低代码、端到端,一小时构建IoT示例场景,声网发布灵隼物联网云平台
- 模板函数与特化函数实现高效dynamicCast
猜你喜欢

Hezhou air32f103cbt6 development board hands-on Report

《天天数学》连载54:二月二十三日

Three development trends of enterprise application viewed from the third technological revolution

Summer rainbow comes for dinner

Unicom warehousing | all Unicom companies that need to sell their products need to enter the general warehouse first

Optional类的高级使用
![[multithreading] how to implement timer by yourself](/img/a9/dd9489c7a0028dd9d3a6dae9a71deb.png)
[multithreading] how to implement timer by yourself

Problem solving metauniverse, multi communication scheme in online games
详细聊聊MySQL中auto_increment有什么作用

新手必须知道的 Kubernetes 架构
随机推荐
如果我在珠海,到哪里开户比较好?究竟网上开户是否安全么?
Steady! The best posture for thousands of microservices to access Zadig (helm chart)
qt5.14.2连接ubuntu20.04的mysql数据库出错
2022 (第五届)GIS软件技术大会开幕,GIS、IT将加速融合
laravel 关联模型 多态关系
static关键字续、继承、重写、多态
新手必须知道的 Kubernetes 架构
Dynamics 365online lookup lookup field multiple selection
[php8+oracle11g+windows environment without tools] Intranet / no network /win10/php connecting to Oracle database instance
从零实现深度学习框架——LSTM从理论到实战【理论】
Can cdc2.2.1 listen to multiple PgSQL libraries at the same time?
解题元宇宙,网络游戏中的多元通信方案
低代码、端到端,一小时构建IoT示例场景,声网发布灵隼物联网云平台
股票开户安全吗?上海股票开户。
What are the software testing methods and technical knowledge points?
Why does copying files on a shared folder on a local area network (ERP server) result in the loss of the local Internet
[proteus simulation] digital tube display of stepping motor speed
MooseFS基本概念总结
Low code, end-to-end, one hour to build IOT sample scenarios, and the sound network released lingfalcon Internet of things cloud platform
Ce CDC Flink peut - il être utilisé pour la synchronisation incrémentale d'Oracle à MySQL?