Create a sequence
Use the CREATE SEQUENCE statement to create a sequence, which is an object from which users can generate unique numbers.
CREATE SEQUENCE <sequence name> [as <data type> <options>]START WITH <start value>
INCREMENT BY <increment>
no minvalue | minvalue <minimum value>
no maxvalue | maxvalue <maximum value>
cycle | no cycle- The default
minvalueis nominvalue, which is defined to be 1. - The default
maxvalueis nomaxvalueand is the largest value by data type that the sequence can hold. - The default start value is the
minvaluefor an increasing sequence, and themaxvaluefor a decreasing sequence. Thestartvaluemust be within the range of theminvalueandmaxvalue. - The default increment is 1.
- By default, sequences do not cycle.
When a user generates a sequence number, the system increments the sequence independently of the transaction committing or rolling back. Therefore, a rollback does not return the value to the sequence object. If two users concurrently increment the same sequence, the sequence numbers each user acquires might have gaps because the sequence numbers are being generated by the other user.
Sequences also can have gaps because sequence values on the host and SPUs are identified for efficient operation.