|
|
Creating Sequences
A sequence can be used to provide the default value for a domain or a table column, etc.
A sequence returns a series of integer values which is defined by specifying an initial value, a maximum value, an increment and whether the sequence is to be unique or not.
A sequence that has been initialized has a current value, which is returned from the function CURRENT_VALUE. The function NEXT_VALUE is used to initialize a sequence and to subsequently advance the current value of the sequence through its defined series of values.
A unique sequence will never return the same value twice.
Examples of Sequences
Create a sequence that returns odd numbers:
CREATE SEQUENCE seq_1 INITIAL_VALUE = 1 INCREMENT = 2 IN DATABANK userdb;Create a sequence that defines the following series of values: 1, 4, 7, 10, 3, 6, 9, 2, 5, 8:
CREATE UNIQUE SEQUENCE seq_2 INITIAL_VALUE = 1 INCREMENT = 3 MAX_VALUE = 10 IN DATABANK userdb;Create a table that uses a sequence to set a column default value:
CREATE TABLE objinfo (objid INTEGER DEFAULT NEXT_VALUE OF obj_seq, description NCHAR VARYING(1000));
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|