Creates a new sequence. Command introduced in version 2.2.
CREATE SEQUENCE <sequence> TYPE <CACHED|ORDERED> [START <start>] [INCREMENT <increment>] [CACHE <cache>]
<sequence>Logical name for the sequence to cache.
TYPEDefines the sequence type. Supported types are,
CACHEDFor sequences where it caches N items on each node to improve performance when you require many calls to the
.next()method. (Bear in mind, this may create holes with numeration).
ORDEREDFor sequences where it draws on a new value with each call to the
STARTDefines the initial value of the sequence.
INCREMENTDefines the increment for each call of the
CACHEDefines the number of value to pre-cache, in the event that you use the cached sequence type.
CYCLEDefines if sequence will restart from
LIMITvalue reached. Default value is
LIMITDefines limit value sequence can reach. After limit value is reached cyclic sequences will restart from START value, while non cyclic sequences will throw message that limit is reached.
ASC | DESCDefines order of the sequence.
ASCdefines that next sequence value will be
currentValue + incrementValue, while
DESCdefines that next sequence value will be
currentValue - incrementValue(assuming that limit is not reached). Default value is
Create a new sequence to handle id numbers:
CREATE SEQUENCE idseq TYPE ORDERED
Use the new sequence to insert id values
INSERT INTO Account SET id = sequence('idseq').next()
For more information, see