当前位置:网站首页>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,'沁沁');
边栏推荐
- 语音社交软件开发——充分发挥其价值
- SQL Outer Join Intersection, Union, Difference Query
- Offensive World-PWN-new_easypwn
- 【OpenCV】-仿射变换
- 如何修改管理工具client_encoding
- Import Excel/CSV from Sub Grid within Dynamics 365
- Go编译原理系列6(类型检查)
- nyoj86 找球号(一) set容器和二分 两种解法
- Leetcode刷题——623. 在二叉树中增加一行
- RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
猜你喜欢
The JVM collection that Alibaba's top architects have summarized for many years, where can't I check it!
three objects are arranged in a spherical shape around the circumference
【MindSpore Easy-Diantong Robot-01】You may have seen many knowledge quiz robots, but this one is a bit different
NowCoderTOP35-40 - continuous update ing
Leetcode刷题——623. 在二叉树中增加一行
SD NAND Flash简介!
字节一面:TCP 和 UDP 可以使用同一个端口吗?
这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口
Our Web3 Entrepreneurship Project, Yellow
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
随机推荐
SkiaSharp 之 WPF 自绘 投篮小游戏(案例版)
three objects are arranged in a spherical shape around the circumference
阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!
气象数据数据处理实例——matlab字符串切割匹配与R语言日期匹配(数据拼接)
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
Common operations of oracle under linux and daily accumulation of knowledge points (functions, timed tasks)
JS introduction to reverse the recycling business network of learning, simple encryption mobile phone number
uniapp connect ibeacon
Create a Dapp, why choose Polkadot?
In-depth understanding of timeout settings for Istio traffic management
Go compilation principle series 6 (type checking)
linux下oracle常见操作以及日常积累知识点(函数、定时任务)
SMB + SMB2: Accessing shares return an error after prolonged idle period
How can project cost control help project success?
第四章:activiti RuntimeService设置获和取流程变量,及与taskService的区别,开始和完成任务时设置流程变量[通俗易懂]
How does the official account operate and maintain?Public account operation and maintenance professional team
The JVM collection that Alibaba's top architects have summarized for many years, where can't I check it!
【MindSpore Easy-Diantong Robot-01】You may have seen many knowledge quiz robots, but this one is a bit different
数据中台建设(十):数据安全管理
three.js debugging tool dat.gui use