Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 27th, 2008, 08:08 PM
Authorized User
 
Join Date: Oct 2006
Location: , , .
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!


Reply With Quote
  #2 (permalink)  
Old March 31st, 2008, 01:31 AM
Authorized User
 
Join Date: Sep 2003
Location: Delhi, Delhi, India.
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
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 Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:58 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.