Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2008, 08:08 PM
Authorized User
 
Join Date: Oct 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default suggestion for better processing using cursor

Hi,

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:
         country_code
         source_code
         apply_order

      TARGET table has the following fields:
         country_code_o
         source_code_o

 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
  FOR
  SELECT
    country_code,
    source_code,
  FROM SOURCE ORDER BY apply_order

  DECLARE
     @apply_order(),
     @country_code(),
     @source_code()

  BEGIN TRANSACTION
  OPEN mycursor
  FETCH mycursor INTO @apply_order, @country_code, @source_code

  --UPDATE the TARGET table now

         UPDATE TARGET
         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!


 
Old March 31st, 2008, 01:31 AM
Authorized User
 
Join Date: Sep 2003
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prabodh_mishra
Default

I'm sorry but there must be something missing here. Are u updating the target or inserting new rows?
If you are updating where is 'WHERE' clause and if inserting you can use
"INSERT INTO TARGET SELECT country_code, source_code FROM SOURCE ORDER BY apply_order"




Prabodh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Magnetic Cursor - Target Area Cursor? gcarcass .NET Framework 2.0 1 May 5th, 2008 07:20 AM
Suggestion for better / faster processing elygp SQL Server 2000 2 February 13th, 2008 10:47 PM
Need your suggestion... popp SQL Language 1 July 2nd, 2007 01:44 AM
Suggestion Snib Forum and Wrox.com Feedback 2 April 10th, 2004 04:27 PM
Suggestion Ben Horne Flash (all versions) 4 April 7th, 2004 09:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.