SEQUENCES

The SEQUENCES table provides information about sequences. The sequences feature is modeled on a similar feature in MariaDB.

  1. USE INFORMATION_SCHEMA;
  2. DESC SEQUENCES;

The output is as follows:

  1. +-----------------+--------------+------+------+---------+-------+
  2. | Field | Type | Null | Key | Default | Extra |
  3. +-----------------+--------------+------+------+---------+-------+
  4. | TABLE_CATALOG | varchar(512) | NO | | NULL | |
  5. | SEQUENCE_SCHEMA | varchar(64) | NO | | NULL | |
  6. | SEQUENCE_NAME | varchar(64) | NO | | NULL | |
  7. | CACHE | tinyint(0) | NO | | NULL | |
  8. | CACHE_VALUE | bigint(21) | YES | | NULL | |
  9. | CYCLE | tinyint(0) | NO | | NULL | |
  10. | INCREMENT | bigint(21) | NO | | NULL | |
  11. | MAX_VALUE | bigint(21) | YES | | NULL | |
  12. | MIN_VALUE | bigint(21) | YES | | NULL | |
  13. | START | bigint(21) | YES | | NULL | |
  14. | COMMENT | varchar(64) | YES | | NULL | |
  15. +-----------------+--------------+------+------+---------+-------+
  16. 11 rows in set (0.00 sec)

Create a sequence test.seq and query the next value of the sequence:

  1. CREATE SEQUENCE test.seq;
  2. SELECT nextval(test.seq);
  3. SELECT * FROM sequences\G

The output is as follows:

  1. +-------------------+
  2. | nextval(test.seq) |
  3. +-------------------+
  4. | 1 |
  5. +-------------------+
  6. 1 row in set (0.01 sec)

View all sequences:

  1. SELECT * FROM SEQUENCES\G

The output is as follows:

  1. *************************** 1. row ***************************
  2. TABLE_CATALOG: def
  3. SEQUENCE_SCHEMA: test
  4. SEQUENCE_NAME: seq
  5. CACHE: 1
  6. CACHE_VALUE: 1000
  7. CYCLE: 0
  8. INCREMENT: 1
  9. MAX_VALUE: 9223372036854775806
  10. MIN_VALUE: 1
  11. START: 1
  12. COMMENT:
  13. 1 row in set (0.00 sec)