2
0

README.sequence_generators 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. -------------------
  2. Sequence generators
  3. -------------------
  4. Function:
  5. A sequence generator is a mechanism for generating successive exact
  6. numeric values, one at a time. A sequence generator is a named schema
  7. object.
  8. Syntax rules:
  9. CREATE { SEQUENCE | GENERATOR } <name>
  10. DROP { SEQUENCE | GENERATOR } <name>
  11. SET GENERATOR <name> TO <start_value>
  12. ALTER SEQUENCE <name> RESTART WITH <start_value>
  13. GEN_ID (<name>, <increment_value>)
  14. NEXT VALUE FOR <name>
  15. Type:
  16. INTEGER in dialect 1, BIGINT in dialect 3
  17. Example(s):
  18. 1. CREATE SEQUENCE S_EMPLOYEE;
  19. 2. ALTER SEQUENCE S_EMPLOYEE RESTART WITH 0;
  20. 3. SELECT GEN_ID(S_EMPLOYEE, 1) FROM RDB$DATABASE;
  21. 4. INSERT INTO EMPLOYEE (ID, NAME) VALUES (NEXT VALUE FOR S_EMPLOYEE, 'John Smith');
  22. Note(s):
  23. 1. SEQUENCE is a syntax term declared in the SQL specification, while
  24. GENERATOR is a legacy InterBase syntax term. It's recommended to use
  25. the standard SEQUENCE syntax in your applications.
  26. 2. Currently, increment values not equal to 1 (one) could be used only via
  27. the GEN_ID function. The future versions are expected to provide full
  28. support for SQL-99 sequence generators (which allows the required
  29. increment values to be specified at the DDL level), so it's recommended
  30. to get new sequential values via NEXT VALUE FOR value expression instead
  31. of the GEN_ID function, unless it's vitally important to use other
  32. increment values.
  33. 3. GEN_ID(<name>, 0) allows you to retrieve the current sequence value,
  34. but it should be never used in insert/update statements, as it produces a
  35. high risk of uniqueness violations in a concurrent environment.