Db2: How to update the current value of a sequence

Sivapandian Jayakumar picture Sivapandian Jayakumar · Jan 31, 2018 · Viewed 16.6k times · Source

We use a sequence in a Db2 database. Recently, we have migrated the data from an AIX server to a Linux server. During that the latest number of that sequence was not moved to the Linux system. As a consequence, we are seeing duplicates values now.

Here is how we use the sequence:

SELECT NEXTVAL FOR SEQ_YFS_ORDER_NO FROM SYSIBM.SYSDUMMY1

The current value of the sequence on Linux is 100092142. How can I update it to the current value that we have on the AIX system, i.e to (100110960)?

Answer

data_henrik picture data_henrik · Jan 31, 2018

You can modify the sequence using ALTER SEQUENCE. An option offered by ALTER SEQUENCE is to RESTART it with a specific value. Try something like this:

ALTER SEQUENCE SEQ_YFS_ORDER_NO RESTART WITH 100110960

Also note that sequence numbers typically are cached. This may lead to a gap and could have caused the issue during the migration.