Restart DB2 Auto-Increment Primary Key

To change the starting value of an auto-increment primary key in a DB2 database table, follow these steps:

  1. Firstly, connect to the DB2 database and select the table to be modified.
  2. To change the starting value of an auto-increment primary key, use the following SQL statement:
ALTER TABLE table_name ALTER COLUMN column_name RESTART WITH new_start_value

In the above statement, replace table_name with the name of the table to be modified, column_name with the name of the column containing the auto-increment primary key, and new_start_value with the new starting value to be set.

  1. Execute the above SQL statement to modify the starting value of the auto-increment primary key.

Please be aware that once the starting value of an auto-increment primary key has been modified, it cannot be set back to a value that has been previously used. Therefore, before carrying out the above steps, make sure to select a starting value that has not been used before.

bannerAds