permaculture playing cards*
The moose likes JDBC and the fly likes Determined identity key value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Determined identity key value" Watch "Determined identity key value" New topic
Author

Determined identity key value

Sub swamy
Ranch Hand

Joined: Oct 02, 2002
Posts: 121
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
Sheriff

Joined: Oct 13, 2005
Posts: 38046
    
  22
select max(id) from my_table???
Sub swamy
Ranch Hand

Joined: Oct 02, 2002
Posts: 121
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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

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.


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Determined identity key value
 
Similar Threads
Hibernate question: persistent identity
Hibernate Insert Error
Peter, please review LockManager
Primary Key in Entity Beans
Using EJB and Oracle