当前位置:网站首页>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 !
边栏推荐
- Is it safe to open a stock account? Shanghai stock account opening.
- 泰山OFFICE技术讲座:一行中所有元素高度相同
- The third day
- 客户端可以连接远程mysql
- 【无工具搭建PHP8+oracle11g+Windows环境】内网/无网络/Win10/PHP连接oracle数据库实例
- Laravel 创建自己的 Facade 扩展 geoip 根据 IP 获取国家、地域、城市信息
- 掌握这28张图,面试再也不怕被问TCP知识了
- If you master these 28 charts, you will no longer be afraid to be asked about TCP knowledge during the interview
- Can the flick CDC be used for incremental synchronization from Oracle to MySQL
- Static keyword continuation, inheritance, rewrite, polymorphism
猜你喜欢
![Realizing deep learning framework from zero -- LSTM from theory to practice [theory]](/img/ac/164140eff1a6518d49ce25599d9c7b.png)
Realizing deep learning framework from zero -- LSTM from theory to practice [theory]

联通入库|需要各地联通公司销售其产品的都需要先入总库

What are the software testing methods and technical knowledge points?

Low code, end-to-end, one hour to build IOT sample scenarios, and the sound network released lingfalcon Internet of things cloud platform

Optional类的高级使用

科大讯飞 AI 学习机暑期新品发布会 AI + 教育深度结合再创产品新高度

Vs2013 how to make the program run on other computers

为什么要同时重写hashcode和equals方法之简单理解

Free PDF to word software sharing, these software must know!

一键式文件共享软件Jirafeau
随机推荐
便携式4K音视频会议终端一体机带8倍数字变焦
英语没学好到底能不能做coder,别再纠结了先学起来
26岁,0基础转行软件测试,从月薪3k到16k,我整理的超全学习指南
Analyze apache SH script
The soft youth under the blessing of devcloud makes education "smart" in the cloud
這個flink cdc可以用在做oracle到mysql的,增量同步嗎
MySQL lock common knowledge points & summary of interview questions
IFLYTEK AI learning machine summer new product launch AI + education depth combination to create a new height of products
static关键字续、继承、重写、多态
Efficient implementation of dynamiccast with template function and specialization function
Grep工具
关于深度学习的概念理解(笔记)
为什么要同时重写hashcode和equals方法之简单理解
Optional类的高级使用
Day9 - user registration and login
Day9 ---- 用户注册与登录
Can you be a coder if you don't learn English well? Stop worrying and learn it first
【Proteus仿真】步进电机转速数码管显示
Spark集群安装
服务器快速搭建AList集成网盘网站【宝塔面板一键部署AList】