Using IDENT_CURRENT
is not a good idea. If there are concurrent transactions, the returned value might not be your last inserted id, but the last inserted id of another transaction!
Use the JDBC getGeneratedKey
facility to retrieve the generated id of the first INSERT
and use the retrieved value in the second INSERT
, or use SCOPE_IDENTITY()
in the second INSERT
. With SCOPE_IDENTITY()
be sure that you are executing both statements in the same transaction.
See also: How to get the insert ID in JDBC?