I have two tables TARGET and SOURCE. I need to UPDATE rows of SOURCE table and insert those updated rows into TARGET table and then delete original rows from SOURCE. Currently I'm first updating SOURCE table completely through SP and then doing Move operation in another SP.
BEGIN P1:
insert into TARGET(select * from SOURCE where col=someValue)
delete from SOURCE where col=someValue;
END P1
I also tried something like
insert into TARGET(SELECT * FROM OLD TABLE(DELETE FROM SOURCE WHERE col=someValue))
but this didn't work in SP.
I think this is common scenario e.g. History/Archive Table and must be having solution in DB2. Can anybody tell how can I achieve this without affecting performance? I mean SP should not take long time to run. Also can I remove redundant update SP. Instead Can I directly insert updated rows into TARGET and delete corresponding rows from SOURCE. Also I've been advised to make the Delete and Insert operation in single transaction. Will that cause any performance loss?
Targetwithout the intermediate table. - Clockwork-Musecol, and must it be unique? If it's not going to be unique, you need to use some sort of flag value, so you can tell which rows have been inserted intoTARGET, or you risk inserting rows intoSOURCEafter theINSERT, but before theDELETE... with the expected results. Although, don't discount the possibility that the SP may still perform acceptably without attempting it. - Clockwork-Muse