The CREATE SEQUENCE statement (create_sequence_statement) defines a database object that supplies integer values (number generator). In the following description, this object is referred to as a sequence.
<create_sequence_statement> ::= CREATE
SEQUENCE [<schema_name>.]<sequence_name>
[INCREMENT BY <integer>]
[START WITH <integer>]
[MAXVALUE <integer> | NOMAXVALUE] [MINVALUE <integer> |
NOMINVALUE]
[CYCLE | NOCYCLE]
[CACHE <unsigned_integer>
| NOCACHE]
[ORDER | NOORDER]
The sequence names sequence_name can be specified in any order.
The current user must be a RESOURCE user or database administrator (DBA user) and becomes the owner of the sequence. If a schema schema_name is not specified, the current schema is used.
The sequence is assigned to the schema that has been determined implicitly or specified explicitly. The current user must have the CREATEIN privilege for this schema. The sequence name must be different from the names of all the sequences that already exist in the schema.
The integer values generated by the sequence can be used to assign key values.
Defines the difference between the next sequence value and the last value assigned. A negative value for INCREMENT BY generates a descending sequence. The value 1 is used if no value is assigned.
Defines the first sequence value. If no value is specified, the value specified for MAXVALUE or –1 is used for descending sequences and the value specified for MINVALUE or 1 for ascending sequences.
· MINVALUE: Defines the smallest value generated by the sequence. If no value is defined for MINVALUE, the smallest integer value that can be represented with 38 digits is used.
· MAXVALUE: Defines the largest value generated by the sequence. If no value is defined for MAXVALUE, the largest integer value that can be represented with 38 digits is used.
If neither CYCLE nor NOCYCLE is specified, NOCYCLE is assumed.
· CYCLE: MINVALUE is produced for ascending sequences after MAXVALUE has been assigned. MAXVALUE is produced for ascending sequences after MINVALUE has been assigned.
· NOCYCLE: a request for a sequence value fails if the end of the sequence has already been reached, that is, if MAXVALUE has been assigned for ascending sequences or MINVALUE for descending sequences.
If neither CACHE nor NOCACHE is specified, CACHE 20 is assumed.
· CACHE: access to the sequence can be accelerated because the defined number of sequence values is held in the memory.
· NOCACHE: no sequence values are defined beforehand.
Specifying ORDER or NOORDER has no effect.
Sequence values can be specified using CURRVAL and NEXTVAL (Specification of Values). In this way, you can interrogate or increase the current counter value.