Home > Database > Mysql Tutorial > What is the use of mysql sequence?

What is the use of mysql sequence?

little bottle
Release: 2019-05-29 16:56:04
Original
3291 people have browsed it

What is the use of mysql sequence?

MySQL sequence is a set of integers: 1, 2, 3, etc. Since a data table can only have one field with an auto-increment primary key, if you want to implement other fields as well To achieve automatic increase, you can use MySQL sequences to achieve it.

The simplest way to use sequences in MySQL is to use MySQL AUTO_INCREMENT to define columns.

In the following example, the insect data table is created. The ID in the insect table can be automatically increased without specifying a value.

mysql> CREATE TABLE昆虫> CREATE TABLE昆虫
    - >(- > ( 
    - > id INT UNSIGNED NOT NULL AUTO_INCREMENT,- > id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
    - > PRIMARY KEY(id),- > PRIMARY KEY (id ),
    - > name VARCHAR(30)NOT NULL,#type of insect- > name VARCHAR (30 )NOT NULL ,#type of insect 
    - > date DATE NOT NULL,#date收集- > date DATE NOT NULL ,#date收集 
    - > origin VARCHAR(30)NOT NULL#在哪里收集- > origin VARCHAR (30 )NOT NULL #在哪里收集
););
查询OK,0行受影响(0.02秒)查询OK ,0 行受影响(0.02 秒) 
mysql> INSERT INTO昆虫(id,name,date,origin)VALUES> INSERT INTO昆虫(id ,名称,日期,来源)价值观
    - >(NULL,'家蝇','2001-09-10','厨房'),- > (NULL ,'家蝇' ,'2001-09-10' ,'厨房' ), 
    - >(NULL,'millipede','2001-09-10','车道'),- > (NULL ,'millipede' ,'2001-09-10' ,'车道' ), 
    - >(NULL,'蚱蜢','2001-09-10','前院');- > (NULL ,'蚱蜢' ,'2001-09-10' ,'前院' ); 
查询OK,3行受影响(0.02秒)查询OK ,3 行受影响(0.02 秒) 
记录:3个重复:0个警告:0记录:3个重复:0个警告:0       
mysql> SELECT * FROM昆虫ORDER BY id;> SELECT * FROM昆虫ORDER BY id ;
+ ---- + ------------- + ------------ + ------------ ++ ---- + ------------- + ------------ + ------------ +
| id | 名字| 日期| 来源|| id | 名字         | 日期        | 来源      |
+ ---- + ------------- + ------------ + ------------ ++ ---- + ------------- + ------------ + ------------ +
| 1 | 家蝇| 2001-09-10 | 厨房|| 1 | 家蝇     | 2001 - 09 - 10 | 厨房     |     
| 2 | 千足虫| 2001-09-10 | 车道|| 2 | 千足虫    | 2001 - 09 - 10 | 车道    |     
| 3 | 蚱蜢| 2001-09-10 | 前院|| 3 | 蚱蜢| 2001 - 09 - 10 | 前院|     
+ ---- + ------------- + ------------ + ------------ ++ ---- + ------------- + ------------ + ------------ +
3组(0.00秒)3 排在组(0.00 秒)
Copy after login

The above is the detailed content of What is the use of mysql sequence?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template