当前位置:网站首页>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,'沁沁');
边栏推荐
- Where is your most secretive personality?
- 【MindSpore Easy-Diantong Robot-01】You may have seen many knowledge quiz robots, but this one is a bit different
- [Android] How to use RecycleView in Kotlin project
- 第四章:redis 数组结构的set和一些通用命令「建议收藏」
- The fuse: OAuth 2.0 four authorized login methods must read
- 企业的数字化转型到底是否可以买来?
- 语音社交软件开发——充分发挥其价值
- [强网杯2022]WP-UM
- Chapter 5: Multithreaded Communication—wait and notify
- [Strong Net Cup 2022] WP-UM
猜你喜欢

2022 Huashu Cup Mathematical Modeling Question A Optimization Design Ideas for Ring Oscillators Code Sharing

数据可视化(二)

012_SSS_ Improving Diffusion Model Efficiency Through Patching

Getting started with Polkadot parachain development, this article is enough

Login function and logout function (St. Regis Takeaway)

MySQL事务

Leetcode刷题——623. 在二叉树中增加一行

FPGA:开发环境Vivado的使用

电竞、便捷、高效、安全,盘点OriginOS功能的关键词

Create a Dapp, why choose Polkadot?
随机推荐
什么是 DevOps?看这一篇就够了!
RT - Thread record (a, RT, RT Thread version - Thread Studio development environment and cooperate CubeMX quick-and-dirty)
PHP operation mangoDb
[Android] How to use RecycleView in Kotlin project
如何测试一下现场的备机失败,转发主机的场景?
In-depth understanding of timeout settings for Istio traffic management
First Decentralized Heist?Loss of nearly 200 million US dollars: analysis of the attack on the cross-chain bridge Nomad
What are the standards for electrical engineering
SMB + SMB2: Accessing shares return an error after prolonged idle period
How to choose coins and determine the corresponding strategy research
STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)
华为轻量级神经网络架构GhostNet再升级,GPU上大显身手的G-GhostNet(IJCV22)
RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
Our Web3 Entrepreneurship Project, Yellow
告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来
Complete image segmentation efficiently based on MindSpore and realize Dice!
攻防世界-PWN-new_easypwn
19.3 restart the Oracle environment
What is SPL?
如何选币与确定对应策略研究