Skip Top Menu Navigation
Skip Top Menu Navigation

The FREE Enterprise Open Source Database

  Software Documentation Tools Interfaces Administration Development
 

 
You Are Here:  SAP DB > Documentation > How To > Number Generator > CREATE SEQUENCE statement

SAP DB is now SAP MaxDB! For more information, visit the SAP MaxDB pages in the SAP Developer Network.

CREATE SEQUENCE Statement

Use

You create a number generator the values of which can be determined by specifying NEXTVAL and CURRVAL.

For an INSERT or UPDATE statement, both the last used and next value in the sequence can be entered in any column of any table providing the data type of the column allows this. However, it is not possible to define the last used or next value of a sequence as the default value of a column. The value must always be specified explicitly.

Both the last used and next value in the sequence can be selected. They are therefore also available for use in the application.

Procedure

You create a sequence with the CREATE SEQUENCE statement. For this, you define, among other things, a name and an initial value (optional, system default is 1). In addition, you specify how the next value in the sequence is to be generated, for example +1 (system default) or –5.

<sequence_name>.NEXTVAL Next value in the sequence
<sequence_name>.CURRVAL Last value determined within the current session using <sequence_name>.NEXTVAL

If <sequence_name>.NEXTVAL has not been used yet within the current session, specification of <sequence_name>.CURRVAL is invalid.

Up to and including SAP DB version 7.3.0.17, there were problems using sequence values. As a result, you are advised to use SAP DB version 7.3.0.18 or higher for the use of sequence values.

Examples for the multiple use of a sequence



Search / Contact Info

Questions or comments about the Web site? Contact the webmaster.