Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 February 12th, 2008, 08:44 PM
Authorized User
 
Join Date: Oct 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default Suggestion for better / faster processing

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 February 12th, 2008, 10:06 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

INSERT INTO TARGET (country_code_o, source_code_o)
SELECT country_code, source_code from SOURCE ORDER BY apply_order



========================
Scott Klein
Author of:
Professional SQL Server 2005 XML
Professional WCF Programming: .NET Development with the Windows Communication Foundation
Professional LINQ
========================
 
Old February 13th, 2008, 10:47 PM
Authorized User
 
Join Date: Oct 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply, but my data processing is not supposed to INSERT records to TARGET table, but to UPDATE the fields of TARGET table with values from SOURCE table. Updating must be according to apply_order field of the SOURCE table.

Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
suggestion for better processing using cursor elygp SQL Language 1 March 31st, 2008 01:31 AM
which is faster pegasus51 Ajax 3 December 30th, 2007 08:56 AM
They Want It To Be Faster! kindler Access 7 December 20th, 2005 10:54 AM
c++ faster than Pascal IvAnR C++ Programming 5 August 6th, 2005 12:08 AM
Any faster? Ben Access VBA 19 March 12th, 2004 07:04 PM





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