SEQUENCES

SEQUENCES 表提供了有关序列的信息。TiDB 中序列的功能是参照 MariaDB 中的类似功能来实现的。

  1. USE INFORMATION_SCHEMA;
  2. DESC SEQUENCES;

输出结果如下:

  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)

创建一个名为 test.seq 的序列,并查询这个序列的下一个值:

  1. CREATE SEQUENCE test.seq;
  2. SELECT NEXTVAL(test.seq);

输出结果如下:

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

查询数据库中的所有序列:

  1. SELECT * FROM SEQUENCES\G

输出结果如下:

  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)