CREATE SERIAL

Serial is an object that creates a unique sequence number, and has the following characteristics.

The serial is useful in creating a unique sequence number in multi-user environment.

Generated serial numbers are not related with table so, you can use the same serial in multiple tables.

All users including PUBLIC can create a serial object. Once it is created, all users can get the number by using CURRENT_VALUE and NEXT_VALUE.

Only owner of a created serial object and DBA can update or delete a serial object. If an owner is PUBLIC, all users can update or delete it.

Description

You can create a serial object in the database by using the CREATE SERIAL statement. For how to write serial name, Identifier.

Syntax

CREATE SERIALserial_name

[ START WITHinitial ]

[ INCREMENT BYinterval]

[ MINVALUEmin | NOMINVALUE ]

[ MAXVALUEmax | NOMAXVALUE ]

[ CACHEinteger | NOCACHE ]

serial_identifier: Specifies the name of the serial to be generated.

START WITHinitial: Specifies the initial value of serial with 38 digits or less. The default value of ascending serial is 1 and that of descending serial is -1.

INCREMENT BYinterval: Specifies the increment of the serial. You can specify any integer with 38 digits or less except zero at interval. The absolute value of the interval must be smaller than the difference between MAXVALUE and MINVALUE. If a negative number is specified, the serial is in descending order otherwise, it is in ascending order. The default value is 1.

MINVALUE: Specifies the minimum value of the serial, with 38 digits or less. MINVALUE must be smaller than or equal to the initial value and smaller than the maximum value.

NOMINVALUE: 1 is set automatically as a minimum value for the ascending serial -(10)38 for the descending serial.

MAXVALUE: Specifies the maximum number of the serial with 38 digits or less. MAXVALUE must be smaller than or equal to the initial value and greater than the minimum value.

NOMAXVALUE: (10)37 is set automatically as a maximum value for the ascending serial -1 for the descending serial.

CYCLE: Specifies that the serial will be generated continuously after reaching the maximum or minimum value. When a serial in ascending order reaches the maximum value, the minimum value is created as the next value; when a serial in descending order reaches the minimum value, the maximum value is created as the next value.

NOCYCLE: Specifies that the serial will not be generated any more after reaching the maximum or minimum value. The default value is NOCYCLE.

CACHE: Stores as many serials as the number specified by "integer" in the cache to improve the performance of the serials and fetches a serial value when one is requested. If all cached values are used up, as many serials as "integer" are fetched again from the disk to the memory. If the database server stops accidently, all cached serial values are deleted. For this reason, the serial values before and after the restart of the database server may be discontinuous. Because the transaction rollback dose not affect the cached serial values, the request for the next serial will return the next value of the value used (or fetched) lastly when the transaction is rolled back. The "integer" after the CACHE keyword cannot be omitted. If the "integer" is equal to or smaller than 1, the serial cache is not applied.

NOCACHE: Specifies that the serial cache is not used, and serial values are updated and retrieved from a disk upon every request.

Example 2

The following example shows how to create the athlete_idx table to store athlete codes and names and then create an instance by using the order_no. NEXT_VALUE increases the serial number and returns its value.