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 > transfer (insert) data from one table to another table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-22-09, 12:16
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
transfer (insert) data from one table to another table

2 tables have almost same structure but table2 has additional col - PROD_ID. How do I transfer data from table1 to table2 and set PROD_ID to 'XXX' at the same time? This what i have but i don't think it's right:

insert data into DBA.table2
from (
PROD_ID = ‘XXX’
, select * from DBA.XXX_table1);

thanks in advance
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #2 (permalink)  
Old 04-22-09, 12:18
rdutton rdutton is offline
Registered User
 
Join Date: Dec 2008
Posts: 76
insert into table2(prod_id, a,b,c,d) select 'xxx', a, b, c, d from table1

Last edited by rdutton; 04-22-09 at 12:22.
Reply With Quote
  #3 (permalink)  
Old 04-22-09, 13:18
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
Quote:
Originally Posted by rdutton
insert into table2(prod_id, a,b,c,d) select 'xxx', a, b, c, d from table1
I did not want to list all cols from table1 as there are many, but it is ok. Thanks so much
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #4 (permalink)  
Old 04-22-09, 13:26
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
If columns of table2 are same as table1 except adding prod_id at the first or last, you may want to do like:

insert into table2 select 'xxx', t1.* from table1 t1
or
insert into table2 select t1.*, 'xxx' from table1 t1
Reply With Quote
  #5 (permalink)  
Old 04-23-09, 09:20
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
it did work. thanks

now there are 32,000,000 rows in table1 so when i submit this statement i run into a problem:

During SQL processing it returned: SQL0964C The transaction log for the database is full. SQLSTATE=57011

I increased db cfg params:
LOGFILSIZ = 4096 (from 1024)
LOGPRIMARY) = 60 (from 20)
LOGSECOND) = 40 (from 10)

but still getting this error. And I understand I can not commit while I am doing inserts. How do I resolve this?
Thanks
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #6 (permalink)  
Old 04-23-09, 09:52
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You can use an EXPORT to export the data, then use IMPORT with COMMITCOUNT to insert the data.

Andy
Reply With Quote
  #7 (permalink)  
Old 04-23-09, 12:00
dbadam dbadam is offline
Registered User
 
Join Date: Sep 2004
Posts: 12
You can use Load from cursor.

declare mycur cursor for select XXX,..... from tab1
load from mycur of cursor insert into tab2 nonrecoverable
Reply With Quote
  #8 (permalink)  
Old 04-24-09, 04:53
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Since V8 DB2 has "MERGE". Answers to a lot of problems, also this one
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