当前位置:网站首页>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,'沁沁');
边栏推荐
- FPGA: Basic Getting Started LED Lights Blinking
- three物体围绕一周呈球形排列
- RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
- Chapter 5: Activiti process shunting judgment, judging to go to different task nodes
- Development common manual link sharing
- Oracle 19.3 restart 环境
- 登录功能和退出功能(瑞吉外卖)
- uniapp connect ibeacon
- JS逆向入门学习之回收商网,手机号码简易加密解析
- 单片机:温度控制DS18B20
猜你喜欢
Getting started with Polkadot parachain development, this article is enough
STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)
化繁为简!阿里新产亿级流量系统设计核心原理高级笔记(终极版)
[Strong Net Cup 2022] WP-UM
Jenkins manual (2) - software configuration
用KUSTO查询语句(KQL)在Azure Data Explorer Database上查询LOG实战
2022华数杯数学建模A题环形振荡器的优化设计思路思路代码分享
项目成本控制如何帮助项目成功?
一张图看懂 SQL 的各种 join 用法!
【OpenCV】-仿射变换
随机推荐
[Android]如何使用RecycleView in Kotlin project
three.js调试工具dat.gui使用
一文道清什么是SPL
LeetCode 216. Combined Sum III (2022.08.04)
High-quality DeFi application building guide to help developers enjoy DeFi Summer
我们的Web3创业项目,黄了
Offensive World-PWN-new_easypwn
2022杭电多校 第6场 1008.Shinobu Loves Segment Tree 规律题
Technical dry goods | Hausdorff distance for image segmentation based on MindSpore
【 temperature warning program DE development 】 event driven model instance
第四章:activiti流程中,变量的传递和获取流程变量 ,设置和获取多个流程变量,设置和获取局部流程变量「建议收藏」
阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!
The JVM collection that Alibaba's top architects have summarized for many years, where can't I check it!
秘乐短视频挖矿系统开发详情
RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
反射修改jsessionid实现Session共享
Score interview (1)----related to business
百年北欧奢华家电品牌ASKO智能三温区酒柜臻献七夕,共品珍馐爱意
入门 Polkadot 平行链开发,看这一篇就够了
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从