Firebird Documentation Index → Firebird 2.5 Language Ref. Update → DDL statements → SEQUENCE or GENERATOR |
Table of Contents
Available in: DSQL
Added in: 2.0
Description: Creates a new sequence or generator. SEQUENCE is the SQL-compliant term for what InterBase and Firebird have always called a generator. CREATE SEQUENCE is fully equivalent to CREATE GENERATOR and is the recommended syntax from Firebird 2.0 onward.
Syntax:
CREATE SEQUENCEsequence-name
Example:
create sequence seqtest
Because internally sequences and generators are the same thing, you can freely mix the generator and sequence syntaxes, even when operating on the same object. This is not recommended however.
Sequences (or generators) are always stored as 64-bit integer values, regardless of the database dialect. However:
If the client dialect is set to 1, the server passes generator values as truncated 32-bit values to the client.
If generator values are fed into a 32-bit field or variable, all goes well until the actual value exceeds the 32-bit range. At that point, a dialect 3 database will raise an error whereas a dialect 1 database will silently truncate the value (which could also lead to an error, e.g. if the receiving field has a unique key defined on it).
See also: ALTER SEQUENCE, NEXT VALUE FOR, DROP SEQUENCE
Table of Contents
Available in: DSQL, ESQL
Better alternative: CREATE SEQUENCE
Changed in: 2.0
Description: From Firebird 2.0 onward, the SQL-compliant CREATE SEQUENCE syntax is preferred.
Changed in: 1.0
Description: InterBase reserved only one database page for generators, limiting the total number to 123 (on 1K pages) – 1019 (on 8K pages). Firebird has done away with that limit; you can now create more than 32,000 generators per database.
Available in: DSQL
Added in: 2.0
Description: (Re)initializes a sequence or generator to the given value. SEQUENCE is the SQL-compliant term for what InterBase and Firebird have always called a generator. “ALTER SEQUENCE ... RESTART WITH” is fully equivalent to “SET GENERATOR ... TO” and is the recommended syntax from Firebird 2.0 onward.
Syntax:
ALTER SEQUENCEsequence-name
RESTART WITH<newval>
<newval>
::= A signed 64-bit integer value.
Example:
alter sequence seqtest restart with 0
Careless use of ALTER SEQUENCE is a mighty fine way of screwing up your database! Under normal circumstances you should only use it right after CREATE SEQUENCE, to set the initial value.
See also: CREATE SEQUENCE
Available in: DSQL, ESQL
Better alternative: ALTER SEQUENCE
Description: (Re)initializes a generator or sequence to the given value. From Firebird 2 onward, the SQL-compliant ALTER SEQUENCE syntax is preferred.
Syntax:
SET GENERATORgenerator-name
TO<new-value>
<new-value>
::= A 64-bit integer.
Once a generator or sequence is up and running, you should not tamper with its value (other than retrieving next values with GEN_ID or NEXT VALUE FOR) unless you know exactly what you are doing.
Available in: DSQL
Added in: 2.0
Description: Removes a sequence or generator from the database. Its (very small) storage space will be freed for re-use after a backup-restore cycle. SEQUENCE is the SQL-compliant term for what InterBase and Firebird have always called a generator. DROP SEQUENCE is fully equivalent to DROP GENERATOR and is the recommended syntax from Firebird 2.0 onward.
Syntax:
DROP SEQUENCEsequence-name
Example:
drop sequence seqtest
See also: CREATE SEQUENCE
Available in: DSQL
Added in: 1.0
Better alternative: DROP SEQUENCE
Description: Removes a generator or sequence from the database. Its (very small) storage space will be freed for re-use after a backup-restore cycle.
Syntax:
DROP GENERATORgenerator-name
From Firebird 2.0 onward, the SQL-compliant DROP SEQUENCE syntax is preferred.
Firebird Documentation Index → Firebird 2.5 Language Ref. Update → DDL statements → SEQUENCE or GENERATOR |