How to get the next value to be used in the IDENTITY column

I am using DB2 v9 in LUW.

I have a column defined as follows:

"ID" BIGINT NOT NULL GENERATED BY DEFAULT
AS IDENTITY (START WITH 1, INCREMENT BY 1, CACHE 20,
NO MINVALUE, NO MAXVALUE, NO CYCLE, NO ORDER),

I would like to know how best to determine what next value will be for the identifier column the next time the record is inserted into the table.

I will use this information to write a script to do a sanity check on the table that IDENTITY is still untouched and that its next value is greater than the highest value in the ID column.

I don't want to just reset the value blindly. If the table does not pass the health check, I want to receive a notification so that I can determine what causes the IDENTITY authentication.

+5
3

. , . , , , .

SELECT IDENT_CURRENT ('yourtablename') . , . T-SQL, DB2.

+1

, , . , , , . ( ) 2 , , . , , , , .

, , , , ? ?

, , select max (id) . , , .

+1

If the ID column is set to GENERATED BY ALWAYS, you will not have a problem loading or importing incorrectly. In addition, the IDENTITY_VAL_LOCAL function can be used to get the identifier value.
Read more about this feature here.

0
source

All Articles