Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Identity value from DB2

Status
Not open for further replies.

varshan09

Programmer
Oct 28, 2003
45
IN
Hi,

We are executing a SQL which inserts a row in the table which has defined an identity column through .Net application.

how can we get value of the identity column? Our requirement is to insert the identity column's value in some other table as another insert operation.



Thanks
Varsha
 
Varsha,

normally you probably would use sequences here, they are supported since version 7.2 of DB2 UDB

if that is not possible, you have to distinguish between ALWAYS and BY DEFAULT in the column definition:

1. c1 int not null generated ALWAYS as identity
-> you will have to select it after inserting the data again

2. c1 int not null generated BY DEFAULT as identity
-> you also could create a value by urself or some function (generate_unique()) and insert that and use the same value for the other table.

But as I said, if the value is generally used in multiple tables, use sequences.

Juliane
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top