This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Determined identity key value  RSS feed

 
Sub swamy
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way (programmatically or otherwise) to determine the current value of identity key column in DB2 database.

I cannot afford to insert new records in the table for this verification.
 
Campbell Ritchie
Marshal
Posts: 55687
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
select max(id) from my_table???
 
Sub swamy
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a data load is done - the max value of the identity key column and the identity key may not be the same. So a SELECT MAX() FROM TABLENAME may not always give the correct value.
 
Scott Selikoff
author
Bartender
Posts: 4093
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Off hand you can't. For example, let's say the ID is 5. Now, you insert a record incrementing it to 6. Immediately after the insert, you delete the record.

In this case the current value is 6 but you've deleted the record so max will still return 5. Granted in most database systems its better to disable records by setting some "enable" field to OFF, rather than ever actually deleting data.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!