当前位置:网站首页>MySQL 中 auto_increment 自动插入主键值
MySQL 中 auto_increment 自动插入主键值
2022-08-05 10:28:00 【威威沁沁】
对于整数类型的主键,常搭配自增长 auto_increment 来使用。插入数据对应的字段不给值时,使用最大值+1!!
下面进行演示~~
1️⃣首先创建一个表
create table emp(id int primary key auto_increment , name varchar(20));
注意:atuo_increment 只能作用在设置 主键 列上
2️⃣插入记录
当表中没记录时,我们把对应字段设置null,自动插入 id 的值从 1递增 !!
insert into emp values(null,'张三'),(null,'王五'),(null,'马六');
当表中有记录,自插入 id 值为表中最大值+1
insert into emp values(100,'威威');
insert into emp values(null,'沁沁');
边栏推荐
- 告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来
- 第九章:activit内置用户组设计与组任务分配和IdentityService接口的使用
- High-quality DeFi application building guide to help developers enjoy DeFi Summer
- 如何选币与确定对应策略研究
- In-depth understanding of timeout settings for Istio traffic management
- Offensive World-PWN-new_easypwn
- 【MindSpore Easy-Diantong Robot-01】You may have seen many knowledge quiz robots, but this one is a bit different
- How does the official account operate and maintain?Public account operation and maintenance professional team
- 2022 Huashu Cup Mathematical Modeling Ideas Analysis and Exchange
- 登录功能和退出功能(瑞吉外卖)
猜你喜欢
Still looking for a network backup resources?Hurry up to collect the following network backup resource search artifact it is worth collecting!
登录功能和退出功能(瑞吉外卖)
SQL外连接之交集、并集、差集查询
字节一面:TCP 和 UDP 可以使用同一个端口吗?
The century-old Nordic luxury home appliance brand ASKO smart wine cabinet in the three-temperature area presents the Chinese Valentine’s Day, and tastes the love of the delicacy
教你本地编译运行一个IDEA插件,在IDEA里聊天、下棋、斗地主!
气象数据数据处理实例——matlab字符串切割匹配与R语言日期匹配(数据拼接)
用KUSTO查询语句(KQL)在Azure Data Explorer Database上查询LOG实战
SD NAND Flash简介!
【MindSpore Easy-Diantong Robot-01】You may have seen many knowledge quiz robots, but this one is a bit different
随机推荐
poj2935 Basic Wall Maze (2016xynu暑期集训检测 -----D题)
基于MindSpore高效完成图像分割,实现Dice!
[Unity] [UGUI] [Display text on the screen]
static linking and dynamic linking
MySQL之数据视图
GCC编译的时候头文件搜索规则
这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口
Offensive World-PWN-new_easypwn
多线程(进阶) - 2.5w字总结
poj2287 Tian Ji -- The Horse Racing(2016xynu暑期集训检测 -----C题)
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
three.js调试工具dat.gui使用
反射修改jsessionid实现Session共享
Is digital transformation a business buy-in?
数据可视化(二)
一个栈的输入序列为1 2 3 4 5 的出站顺序的理解
A small test of basic grammar, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, basic grammar of go lang and the use of variables EP02
2022 Hangzhou Electric Power Multi-School Session 6 1008.Shinobu Loves Segment Tree Regular Questions
Data Middle Office Construction (10): Data Security Management
告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来