CREATE SEQUENCE
Syntax
CREATE SEQUENCE [owner_name.]sequence_name
[ START WITH start_value ]
[ INCREMENT BY increment_value ]
[ MAXVALUE max_value | NOMAXVALUE ]
[ MINVALUE min_value | NOMINVALUE ]
[ CYCLE | NOCYCLE ]
Description
The CREATE SEQUENCE command creates a new sequence in the current database.
When CYCLE is specified, a sequence will wrap from the max_value to the min_value for an ascending sequence or from the min_value to a max_value for a descending sequence. When NOCYCLE (the default) is specified, an error is returned when NEXTVAL (see Sequence Values) would exceed the max_value for an ascending sequence or the min_value for a descending sequence.
Example
The following command creates a sequence called myseq. It starts with a value of 5, increments by 5, and returns a maximum value of 50:
CREATE SEQUENCE myseq START WITH 5 INCREMENT BY 5 MAXVALUE 50;
Return Values
Error Code |
Message |
Returned By |
---|---|---|
-20265 |
Sequence with the same name already exists |
CREATE SEQUENCE |
-20268 |
START-WITH/CURRENT-VALUE cannot be greater than MAXVALUE |
CREATE SEQUENCE |
-20269 |
START-WITH/CURRENT-VALUE cannot be less than MINVALUE |
CREATE SEQUENCE |
-20270 |
Invalid sequence MINVALUE specified |
CREATE SEQUENCE |
-20271 |
Invalid sequence INCREMENT specified |
CREATE SEQUENCE |
-20272 |
START-WITH cannot be altered in sequence |
CREATE SEQUENCE |
-20273 |
No options specified for ALTER SEQUENCE |
CREATE SEQUENCE |
-20274 |
Sequence increment has exceeded MAXVALUE |
CREATE SEQUENCE |
-20275 |
Sequence decrement has exceeded MINVALUE |
CREATE SEQUENCE |
-20276 |
Only SELECT and ALTER privileges are valid for sequences |
CREATE SEQUENCE |
See c-tree Plus Error Codes for a complete listing of valid c-tree Plus error values.
See Also