当前位置:网站首页>MySQL - autoincrement constraint of table fields
MySQL - autoincrement constraint of table fields
2022-07-19 16:15:00 【Camellia Populus】
Set the table field value to increase automatically (AUTO_INCREMENT)
AUTO_INCREMENT yes MySQL The only extended integrity constraint , When inserting a new record into a database table , The value on the field automatically generates a unique ID. In specific settings AUTO_INCREMENT When restrained , Only one field in a database table can use this constraint , The data type of this field must be integer .
Because of the settings AUTO_INCREMENT The constrained field will generate a unique ID, Therefore, this field is often set to PK Primary key .
It is very simple to set the automatic increase constraint of a field value in the table , Can be in MySQL Database management system through SQL sentence AUTO_INCREMENT To achieve , Its grammatical form is as follows :
CREATE TABLE tablename(
propName propType AUTO_INCREMENT, ......
);
In the above statement ,tablename The parameter indicates the field name of the non empty constraint to be set ,propName The parameter name is ,propType Attribute type ,propName Fields should be set to automatically add constraints . By default , Field propName From 1 Began to increase , Every time you add a record , The value of this field in the record will be in the previous record ( Or the existing maximum ( Including what once existed )) On the basis of 1.
mysql> create table class4(id int primary key AUTO_INCREMENT, name varchar(64), teacher varchar(64)); # Create table class4, Set up id List as primary key / Self growth
mysql> desc class4; # Query table class4 Constraint information

Be careful : mysql8 in ,AUTO_INCREMENT Must be set as key ( Primary key 、 Both foreign and unique keys )! Otherwise, an error will be reported !
边栏推荐
- The read image of OpenCV notes is de distorted and saved as a new image
- Basic knowledge of Kunpeng code migration tool
- 如何正确重写hashCode方法?
- Identity server 4 uses openid connect to add user authentication (3)
- 深度学习环境配置TensorFlow2+Keras
- 【單片機仿真項目】報警燈(proteus原理圖+keil代碼)
- 在网上办理基金开户业务安全吗?在校大学生求指导
- Financial banking software testing super large strategy, the most popular financial banking big secret cover questions
- Is flush stock trading safe?
- google浏览器chrome无法升级的解决方案
猜你喜欢

云想衣裳花想容,春风拂槛露华浓(浪漫代码实现)

MySQL -调整列的约束

CH549/CH548学习笔记8 - USB Device中断处理

解决MATLAB安装后出现 “License Manager Error -8”(亲测有效)

Conscience products produced by Tencent? Detailed experience of translation function

Definition and usage of callback function and qsort function in C language

A Ye's new hairstyle

MySQL - 表字段的唯一键约束

2022/07 CSI TOOL 安装过程记录

如何正确重写hashCode方法?
随机推荐
Through JMeter pressure measurement surging
Ffifdyop bypasses MD5 for SQL injection
Liquibase学习 - 问题解决:启动报错
STM32+A4988控制步进电机
How to rewrite hashcode method correctly?
Use of promise object in ES6 asynchronous programming
How to implement Mysql to insert if it does not exist and update if it exists
关于双网卡配置后只能一个IP访问的问题
Hash table related knowledge
【单片机仿真项目】数码管依次显示 0 到 5(proteus原理图+keil代码)
Promise 中的 then 第二个参数和 catch 有什么区别?
信创环境下达梦数据库唯一索引异常无法拦截DuplicateKeyException
Open source WPF control library adonisui
Conscience products produced by Tencent? Detailed experience of translation function
ArrayList source code analysis I
CH549/CH548学习笔记8 - USB Device中断处理
同花顺软件线上开户免费吗?开户安全吗?
Reading notes: self cultivation of programmers - Chapter 2
CH549/CH548学习笔记1 - 硬件设计
数学建模--从自然走向理性之路--数学建模概论(学习笔记1)