output - In DB2, perform an update based on insert for large number of rows -


in db2, need insert, then, using results/data insert, update related table. need on million plus records , prefer not lock entire database. so, 1) how 'couple' insert , update statements? 2) how can ensure integrity of transaction (without locking whole she-bang)?

some pseudo-code should clarify

step 1

 insert table1 (neededid, id)        select dynamicvalue, id tablex      needed value null 

step 2

 update table2 set neededid = (get dynamic value inserted)     id = (the id inserted) 

note: in table1, id col not unique, can't filter on find new dynamicvalue

this should more clear (ftr, works, don't it, because i'd have lock tables maintain integrity. great run these statements together, , allow update refer newaddressnumber value.)

/****running top insert first****/*  --insert new address each order not have address id insert addresses     (customerid, addressnumber, address)     select      cust.id,      --get next available addressnumber     ifnull((select max(addy2.addressnumber) addresses addy2  addy2.customerid = cust.id),0) + 1 newaddressnumber,     cust.address customers cust exists (     --find customers @ least 1 order addressnumber null     select 1 orders ord     1=1     , ord.customerid = cust.id     , ord.addressnumber null        )   /*****running update second*****/           update orders ord1 set addressnumber = (             select max(addressnumber) addresses addy3              addy3.customerid = ord1.customerid             )  1=1      , ord1.addressnumber null   

the identity_val_local function non-deterministic function returns assigned value identity column, assignment occurred result of single insert statement using values clause


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -