mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-02-02 10:00:38 +01:00
Documentation for the generator increment.
This commit is contained in:
parent
de7ed79414
commit
5f5feb54e1
@ -392,3 +392,73 @@ ALTER { SEQUENCE | GENERATOR } <sequence name> RESTART [ WITH <value> ]
|
||||
Syntax present in 2.5 for reference:
|
||||
|
||||
ALTER SEQUENCE <sequence name> RESTART WITH <value>
|
||||
|
||||
|
||||
16) Increment for sequences.
|
||||
(Claudio Valderrama)
|
||||
|
||||
For 3.0, the options specified in (15) include INCREMENT:
|
||||
{ CREATE | RECREATE } { SEQUENCE | GENERATOR } <sequence name> [ START WITH <value> ] [ INCREMENT [BY] <increment> ]
|
||||
CREATE OR ALTER { SEQUENCE | GENERATOR } <sequence name> { RESTART | START WITH <value> } [ INCREMENT [BY] <increment> ]
|
||||
ALTER { SEQUENCE | GENERATOR } <sequence name> RESTART [ WITH <value> ] [ INCREMENT [BY] <increment> ]
|
||||
|
||||
This is the increment that's applied to the SQL standard way of working with generators:
|
||||
NEXT VALUE FOR <sequence name>
|
||||
is equivalent to
|
||||
gen_id(<sequence name>, <increment>)
|
||||
|
||||
The default increment for user generators is one and for system generators, zero. This makes possible
|
||||
to apply NEXT VALUE FOR <sys generator>
|
||||
since system generators cannot be changed by user requests now. Example:
|
||||
|
||||
create sequence seq increment 10; -- starts at zero and changes by 10
|
||||
select next value for seq from rdb$database; -- result is 10
|
||||
select gen_id(seq, 1) from rdb$database; -- result is 11, gen_id() is not affected by the increment.
|
||||
|
||||
If the database is new and no trigger has been defined, doing
|
||||
select next value for rdb$procedures from rdb$database;
|
||||
many times will produce zero again and again, because it's a system generator.
|
||||
|
||||
The increment cannot be zero for user generators. Example:
|
||||
|
||||
SQL> create generator g00 increment 0;
|
||||
Statement failed, SQLSTATE = 42000
|
||||
unsuccessful metadata update
|
||||
-CREATE SEQUENCE G00 failed
|
||||
-INCREMENT 0 is an illegal option for sequence G00
|
||||
|
||||
The change in the value of INCREMENT is a feature that takes effect for each request that starts
|
||||
after the change commits. Procedures that are invoked for the first time after the change in INCREMENT
|
||||
will use the new value if they contain NEXT VALUE FOR statements. Procedures that are already
|
||||
running are not affected because they're cached. Procedures relying on NEXT VALUE FOR do not need
|
||||
to be recompiled to see the new increment, but if they are running already, they are loaded and
|
||||
no effect is seen. Of course, gen_id(gen, expression) is not affected by the increment.
|
||||
|
||||
|
||||
17) More security for system objects.
|
||||
(Claudio Valderrama)
|
||||
|
||||
For 3.0, system domains cannot be altered:
|
||||
|
||||
SQL> alter domain rdb$linger type boolean;
|
||||
Statement failed, SQLSTATE = 42000
|
||||
unsuccessful metadata update
|
||||
-ALTER DOMAIN RDB$LINGER failed
|
||||
-System domain RDB$LINGER cannot be modified
|
||||
|
||||
The value of a system generator cannot be changed by user requests:
|
||||
|
||||
SQL> select gen_id(rdb$procedures, 1) from rdb$database;
|
||||
GEN_ID
|
||||
=====================
|
||||
Statement failed, SQLSTATE = 42000
|
||||
System generator RDB$PROCEDURES cannot be modified
|
||||
|
||||
SQL> set generator rdb$procedures to 0;
|
||||
Statement failed, SQLSTATE = 42000
|
||||
unsuccessful metadata update
|
||||
-SET GENERATOR RDB$PROCEDURES failed
|
||||
-System generator RDB$PROCEDURES cannot be modified
|
||||
|
||||
Also, the name RDB$GENERATORS does not refer anymore to an invisible system
|
||||
generator. The name can be applied to an user generator.
|
||||
|
Loading…
Reference in New Issue
Block a user