Discussion:
Next value in indentity
(too old to reply)
netzorro
2007-10-10 18:35:22 UTC
Permalink
Hi all, just a simple question I guess

I want to know the next value the identity column is going to use
Is there a way to do this?

Thanks
netzorro
Knut Stolze
2007-10-10 20:45:43 UTC
Permalink
Post by netzorro
Hi all, just a simple question I guess
I want to know the next value the identity column is going to use
Is there a way to do this?
Maybe it is in the catalog. But what's the use of such information? Even
if you have the number it will be invalid right after you queried it -
other transactions could also insert rows and consume the next value.
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
netzorro
2007-10-10 20:54:29 UTC
Permalink
Post by Knut Stolze
Post by netzorro
Hi all, just a simple question I guess
I want to know the next value the identity column is going to use
Is there a way to do this?
Maybe it is in the catalog. But what's the use of such information? Even
if you have the number it will be invalid right after you queried it -
other transactions could also insert rows and consume the next value.
Thanks for your answer.

It's just because sometimes we move data from one db to other
(export/import)
And I would like to know the sequence value to import out of that range.
Also, what happens if the identity is in number 10 and you have records from
20 to 30 you imported manually.
What happens when the identity reaches 20 ?

Thanks
netzorro
Ian
2007-10-11 03:01:30 UTC
Permalink
Post by netzorro
Post by Knut Stolze
Post by netzorro
Hi all, just a simple question I guess
I want to know the next value the identity column is going to use
Is there a way to do this?
Maybe it is in the catalog. But what's the use of such information? Even
if you have the number it will be invalid right after you queried it -
other transactions could also insert rows and consume the next value.
Thanks for your answer.
It's just because sometimes we move data from one db to other
(export/import)
And I would like to know the sequence value to import out of that range.
You can get this from the catalog (although it may not be completely
accurate if you defined the identity column with a cache).

Better is just to find the maximum value of the column (after importing
your data and reset the identity to start with max+1.
Post by netzorro
Also, what happens if the identity is in number 10 and you have records from
20 to 30 you imported manually.
What happens when the identity reaches 20 ?
Unless there is a unique or primary on the column, nothing happens --
you just get duplicate values (for the identity) in the table.
Blair Kenneth Adamache
2007-10-16 19:57:26 UTC
Permalink
IDENTITY_VAL_LOCAL tracks the most recently used value.

Perhaps SEQUENCE is a better choice:

http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.admin.doc/doc/r0023464.htm
Post by netzorro
Hi all, just a simple question I guess
I want to know the next value the identity column is going to use
Is there a way to do this?
Thanks
netzorro
Loading...