CREATE SEQUENCE t1 start with 1 minvalue 1 maxvalue 10 increment by 1 cache 2 cycle; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `next_value` bigint(21) NOT NULL COMMENT 'next not cached value', `min_value` bigint(21) NOT NULL COMMENT 'min value', `max_value` bigint(21) NOT NULL COMMENT 'max value', `start` bigint(21) NOT NULL COMMENT 'start value', `increment` bigint(21) NOT NULL COMMENT 'increment value', `cache` bigint(21) NOT NULL COMMENT 'cache size', `cycle` tinyint(1) unsigned NOT NULL COMMENT 'cycle state', `round` bigint(21) NOT NULL COMMENT 'How many cycles has been done' ) ENGINE=MyISAM SEQUENCE=1 select next value for t1; next value for t1 1 select next_value,round from t1; next_value round 3 0 select next value for t1; next value for t1 2 select next_value,round from t1; next_value round 3 0 select next value for t1; next value for t1 3 select next_value,round from t1; next_value round 5 0 select next value for t1; next value for t1 4 select next_value,round from t1; next_value round 5 0 select next value for t1; next value for t1 5 select next_value,round from t1; next_value round 7 0 select next value for t1; next value for t1 6 select next_value,round from t1; next_value round 7 0 select next value for t1; next value for t1 7 select next_value,round from t1; next_value round 9 0 select next value for t1; next value for t1 8 select next_value,round from t1; next_value round 9 0 select next value for t1; next value for t1 9 select next_value,round from t1; next_value round 11 0 select next value for t1; next value for t1 10 select next_value,round from t1; next_value round 11 0 select next value for t1; next value for t1 1 select next_value,round from t1; next_value round 3 1 select NEXT VALUE for t1,seq from seq_1_to_20; NEXT VALUE for t1 seq 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 1 10 2 11 3 12 4 13 5 14 6 15 7 16 8 17 9 18 10 19 1 20 drop sequence t1; CREATE SEQUENCE t1 minvalue 1 maxvalue 10 increment by -1 cache 2 cycle engine=aria; select next value for t1; next value for t1 10 select next_value,round from t1; next_value round 8 0 select next value for t1; next value for t1 9 select next_value,round from t1; next_value round 8 0 select next value for t1; next value for t1 8 select next_value,round from t1; next_value round 6 0 select next value for t1; next value for t1 7 select next_value,round from t1; next_value round 6 0 select next value for t1; next value for t1 6 select next_value,round from t1; next_value round 4 0 select next value for t1; next value for t1 5 select next_value,round from t1; next_value round 4 0 select next value for t1; next value for t1 4 select next_value,round from t1; next_value round 2 0 select next value for t1; next value for t1 3 select next_value,round from t1; next_value round 2 0 select next value for t1; next value for t1 2 select next_value,round from t1; next_value round 0 0 select next value for t1; next value for t1 1 select next_value,round from t1; next_value round 0 0 select next value for t1; next value for t1 10 select next_value,round from t1; next_value round 8 1 select NEXT VALUE for t1,seq from seq_1_to_20; NEXT VALUE for t1 seq 9 1 8 2 7 3 6 4 5 5 4 6 3 7 2 8 1 9 10 10 9 11 8 12 7 13 6 14 5 15 4 16 3 17 2 18 1 19 10 20 drop sequence t1; CREATE SEQUENCE t1 start with 8 minvalue 1 maxvalue 10 increment by 1 cache 2 nocycle; select next value for t1; next value for t1 8 select next value for t1; next value for t1 9 select next value for t1; next value for t1 10 select previous value for t1; previous value for t1 10 select next value for t1; ERROR HY000: Sequence 'test.t1' has run out select previous value for t1; previous value for t1 NULL select next value for t1; ERROR HY000: Sequence 'test.t1' has run out drop sequence t1; create sequence s1 start with 1 cache 2 maxvalue 5; select next value for s1; next value for s1 1 select next value for s1; next value for s1 2 select next value for s1; next value for s1 3 select next value for s1; next value for s1 4 select next value for s1; next value for s1 5 select next value for s1; ERROR HY000: Sequence 'test.s1' has run out drop sequence s1; CREATE SEQUENCE t1 start with 1 minvalue 1 maxvalue 100 increment by 1 cache 10; select next value for t1; next value for t1 1 select * from t1; next_value min_value max_value start increment cache cycle round 11 1 100 1 1 10 0 0 flush tables; select next value for t1; next value for t1 11 select nextval(t1); nextval(t1) 12 drop sequence t1; CREATE SEQUENCE t9 start with 1 minvalue 1 maxvalue 10 increment by 1 cache 5 cycle; select previous value for t9; previous value for t9 NULL select next value for t9; next value for t9 1 select previous value for t9, lastval(t9); previous value for t9 lastval(t9) 1 1 select next value for t9; next value for t9 2 select previous value for t9, lastval(t9); previous value for t9 lastval(t9) 2 2 select seq, previous value for t9, NEXT VALUE for t9, previous value for t9 from seq_1_to_20; seq previous value for t9 NEXT VALUE for t9 previous value for t9 1 2 3 3 2 3 4 4 3 4 5 5 4 5 6 6 5 6 7 7 6 7 8 8 7 8 9 9 8 9 10 10 9 10 1 1 10 1 2 2 11 2 3 3 12 3 4 4 13 4 5 5 14 5 6 6 15 6 7 7 16 7 8 8 17 8 9 9 18 9 10 10 19 10 1 1 20 1 2 2 select * from t9; next_value min_value max_value start increment cache cycle round 6 1 10 1 1 5 1 2 drop sequence t9; CREATE SEQUENCE t1 start with 1 minvalue 1 maxvalue 10 increment by 1 cache 5 cycle; select next value for t1; next value for t1 1 select previous value for t1; previous value for t1 1 flush tables; select previous value for t1; previous value for t1 1 drop sequence t1; select previous value for t1; ERROR 42S02: Table 'test.t1' doesn't exist CREATE SEQUENCE t1 start with 5 minvalue 1 maxvalue 10 increment by 1 cache 5 cycle; select previous value for t1; previous value for t1 NULL select next value for t1; next value for t1 5 select previous value for t1; previous value for t1 5 drop sequence t1; CREATE or replace SEQUENCE s1 MINVALUE 1 MAXVALUE 9999999999 INCREMENT BY 1 START WITH 3984356 CACHE 20 CYCLE engine=innodb; show create table s1; Table Create Table s1 CREATE TABLE `s1` ( `next_value` bigint(21) NOT NULL COMMENT 'next not cached value', `min_value` bigint(21) NOT NULL COMMENT 'min value', `max_value` bigint(21) NOT NULL COMMENT 'max value', `start` bigint(21) NOT NULL COMMENT 'start value', `increment` bigint(21) NOT NULL COMMENT 'increment value', `cache` bigint(21) NOT NULL COMMENT 'cache size', `cycle` tinyint(1) unsigned NOT NULL COMMENT 'cycle state', `round` bigint(21) NOT NULL COMMENT 'How many cycles has been done' ) ENGINE=InnoDB SEQUENCE=1 select * from s1; next_value min_value max_value start increment cache cycle round 3984356 1 9999999999 3984356 1 20 1 0 select NEXT VALUE FOR s1; NEXT VALUE FOR s1 3984356 select NEXT VALUE FOR s1; NEXT VALUE FOR s1 3984357 select NEXT VALUE FOR s1; NEXT VALUE FOR s1 3984358 select * from s1; next_value min_value max_value start increment cache cycle round 3984376 1 9999999999 3984356 1 20 1 0 FLUSH TABLES; select * from s1; next_value min_value max_value start increment cache cycle round 3984376 1 9999999999 3984356 1 20 1 0 select NEXT VALUE FOR s1; NEXT VALUE FOR s1 3984376 select * from s1; next_value min_value max_value start increment cache cycle round 3984396 1 9999999999 3984356 1 20 1 0 drop sequence s1; CREATE SEQUENCE t1 start with 5 minvalue 1 maxvalue 10 increment by 1 cache 5 cycle; explain select next value for t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used explain select next value for t1, min_value from t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 drop table t1; CREATE SEQUENCE s1; CREATE TABLE t1 (a int); insert into t1 values (next value for s1); insert into t1 values (next value for s1); select * from t1; a 1 2 drop table t1,s1; CREATE SEQUENCE s1; CREATE TABLE t1 (a int primary key auto_increment, b int default 0) engine=myisam; insert into t1 values (),(),(),(),(),(),(); update t1 set b= next value for s1 where a <= 3; select * from t1; a b 1 1 2 2 3 3 4 0 5 0 6 0 7 0 drop table t1,s1; CREATE OR REPLACE SEQUENCE s1 MINVALUE 1 MAXVALUE 9999999999 INCREMENT BY 1 START WITH 3984356 nocache CYCLE engine='innodb'; select * from s1; next_value min_value max_value start increment cache cycle round 3984356 1 9999999999 3984356 1 0 1 0 select next value for s1; next value for s1 3984356 drop sequence s1; create table t1 (a int); select next value for t1; ERROR 42S02: 'test.t1' is not a SEQUENCE drop table t1; create sequence t1; select next value for t1; next value for t1 1 select next value for t1, min_value; ERROR 42S22: Unknown column 'min_value' in 'field list' drop sequence t1;