当前位置:网站首页>[What is the role of auto_increment in MySQL?】
[What is the role of auto_increment in MySQL?】
2022-07-31 08:29:00 【m0_67402564】
Directory
Source of problem
Many times, the word [auto_increment] will appear in MySQL statements. Most of the time, tables are automatically generated. You will learn it when you first learn the MySQL database. Later, you may forget it gradually.What does effect mean?Here's a summary:
Explanation
auto_increment is used for primary key auto-increment, it starts to grow from 1, when you delete the first record and insert the second data, the primary key value is 2, not 1.
Example:
create table test
(
id int(10) not null auto_increment, – means auto-increment
name varchar(20) not null,
primary key(id)
)
auto_increment = 1; - Indicates the auto-increment starting size-- This way you can create a table test, the id is the auto-increment column
– execute the statement insert into test (name) values ('name');
– you can insert a row of data as: 1 'name'

Notes
When using AUTO_INCREMENT, the following points should be noted:
1, AUTO_INCREMENT is an attribute of the data column, only applicable to the integer type data column.
2, the data column for setting the AUTO_INCREMENT attribute should be a positive sequence, so the data column should be declared as UNSIGNED, so that the number of the sequence can be increased by onetimes.
3, the AUTO_INCREMENT data column must have a unique index to avoid repeated serial numbers (that is, the primary key or part of the primary key).
AUTO_INCREMENT data column must have NOT NULL attribute.
4, the maximum value of the serial number of the AUTO_INCREMENT data column is constrained by the data type of the column. For example, the maximum number of the TINYINT data column is 127, and if UNSIGNED is added, the maximum value is 255.Once the upper limit is reached, AUTO_INCREMENT will fail.
5. When a full table is deleted, MySQL AUTO_INCREMENT will start numbering from 1 again.
This is because when performing a full table operation, MySQL (the best combination with PHP) actually does this optimization operation: first delete all data and indexes in the data table,Then rebuild the data table.
If you want to delete all data rows and keep the sequence number information, you can use a delete command with where to suppress the optimization of MySQL (the best combination with PHP): delete from table_name where 1;
Use last_insert_id() to get the just incremented value.
Description: Part of the content comes from the search and sorting, the purpose is to record the summary and learn to use~
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
- 如何使用mysql binlog 恢复数据
- [MySQL exercises] Chapter 2 Basic operations of databases and data tables
- linux redis6.2.6配置文件
- Calculation example of matlab program iEEE9 node system for power flow calculation of AC-DC hybrid system based on alternate iteration method
- 【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(下) -- 搜索历史
- SSM框架讲解(史上最详细的文章)
- C语言三子棋(井字棋)小游戏
- Failure scenarios of @Transactional annotations
- 《c语言》青蛙跳台阶递归问题
- 动态顺序表的增删查改(C语言实现)
猜你喜欢

Regarding "computing power", this article is worth reading

35-Jenkins-Shared library application

MySQL detailed explanation

Pygame Surface对象

First acquaintance with NK-RTU980 development board

会话技术之Coookie && Session详解

深度理解递归,手撕经典递归问题(汉诺塔,青蛙跳台阶),保姆级教学。

使用MySQL如何查询一年中每月的记录数

正则表达式绕过

PowerCLi 通过自建PXE Server一键esxi7下批量部署常规New-VM
随机推荐
SSM框架讲解(史上最详细的文章)
torch分布式训练
【C#】判断字符串中是否包含指定字符或字符串(Contains/IndexOf)
CY7C68013A之LED闪烁
MySQL安装常见报错处理大全
如何使用mysql binlog 恢复数据
【C#】说说 C# 9 新特性的实际运用
[Interview: Concurrency 37: Multithreading: Thread Pool] Custom Thread Pool
使用PageHelper实现分页查询(详细)
进程和线程的区别&&run和start区别与联系
ZCMU--1862: zbj的狼人杀
0730~Mysql优化
Ubuntu安装Mysql5.7
Spark 在 Yarn 上运行 Spark 应用程序
【云原生与5G】微服务加持5G核心网
数组every和some方法的区别?
控制文本保留几行,末尾省略
使用MySQL如何查询一年中每月的记录数
【插值与拟合】
Visual Studio新功能出炉:低优先级构建