suggestion for better processing using cursor
I hope you could suggest something to improve my data processing...
I have two tables in my database, the SOURCE and the TARGE table. TARGET table must be updated with the records from the SOURCE table following the order of a field in the SOURCE table. To make it clear, the process is like this:
SOURCE table has the following fields:
TARGET table has the following fields:
The fields of TARGET table must be updated with the contents of the SOURCE table but the processing must be according to apply_order field.
To do this, my script goes like this:
DECLARE mycursor CURSOR
FROM SOURCE ORDER BY apply_order
FETCH mycursor INTO @apply_order, @country_code, @source_code
--UPDATE the TARGET table now
SET country_code_o = @country_code,
source_code_o = @source_code
The script is inside a loop and updates all records. The script works fine without errors, but it takes a lot of time processing. I have about 500K of records to process.
Is there any other better way to do this? I cannot simply use
UPDATE TARGET SELECT country_code, source_code FROM SOURCE
as this will violate the rule that processing must follow the apply_order field.
Thanks for your help!