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 秒)
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!