If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > IDENTITY column...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-08-08, 16:13
Blakk_Majik Blakk_Majik is offline
Registered User
 
Join Date: Dec 2008
Posts: 2
IDENTITY column...

I have a table that uses an identity column to auto-generate a primary key.

The problem is that when I do an insert, I need to insert the number into two different tables.

So my question is, how do I capture the value auto-generated in the insert to the first table in order to insert it into the second table?
Reply With Quote
  #2 (permalink)  
Old 12-08-08, 16:26
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Assume the Employee table has a PK of empno, which is an integer defined as a identity column.

select empno from final table (insert into employee (empno, name, salary) values (default, 'Smith', 75000));
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 12-08-08, 16:48
Blakk_Majik Blakk_Majik is offline
Registered User
 
Join Date: Dec 2008
Posts: 2
I understand what you are doing in the insert, but I don't understand the whole thing.

I assume "final table" is the second table I will be inserting into. However, how can I select a value that doesn't exist? I also don't see where you insert the auto-generated number into the second table.

Can you provide a few more details on your example?
Reply With Quote
  #4 (permalink)  
Old 12-08-08, 17:12
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
No, final table is not a real table, it is the contents of the employee table after the data is inserted. Instead of just asking a bunch of questions, try the statement I gave you (on a real table). If you have any specific questions about how final table works, check out the manual.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On