Online Documentation for SQL Manager for DB2

Sequences


A Sequence is a database object from which multiple users can generate unique integers. You can use sequences to automatically generate primary key values. When a sequence number is generated, the sequence is incremented, independent of the transaction being committed or rolled back.

If two users concurrently increment the same sequence, then the sequence numbers each user acquires may have gaps, because sequence numbers are being generated by the other user. One user can never acquire the sequence number generated by another user. After a sequence value is generated by one user, that user can continue to access that value regardless of whether the sequence is incremented by another user.

 

 

Creating Sequences

 

To create a new sequence:

Hint: To create a new sequence, you can also right-click the Sequences node of the DB Explorer tree and select the New Sequence... context menu item.

 

To create a new sequence with the same properties as one of existing sequences has:

Alternatively, you can right-click a sequence in the DB Explorer tree and select the Duplicate Sequence <sequence_name>... context menu item.

 

Duplicate Object Wizard allows you to select the database to create a new sequence in, and to edit the result SQL statement for creating the sequence.

 

 

Editing Sequences

 

To edit an existing sequence:

  • select the sequence for editing in the DB Explorer tree (type the first letters of the sequence name for quick search);
  • right-click the object and select the Edit Sequence <sequence_name>... context menu item, or simply double-click the sequence;
  • edit sequence definition using the appropriate tabs of Sequence Editor.

 

Dropping Sequences

 

To drop a sequence:

  • select the sequence to drop in the DB Explorer tree;
  • right-click the object and select the Drop Sequence <sequence_name>... context menu item;
  • confirm dropping in the dialog window.

 

Note: If more convenient, you can also use the following shortcuts:

Ctrl+N to create a new sequence;

Ctrl+O to edit the selected sequence;

Shift+Del to drop the object from the database.