473,473 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Large Data Extract - Improvements?

3 New Member
Hi everyone,

I've been working on a large data extract and was wandering if anyone could take a look at the following code and offer any reasons why it takes such a long time compared to when i had it seperated out in steps with GO statements in a scheduled job.

It needs to:

1) delete all data on local tables
2) import all data from external source back into local tables
3) rebuild indexes on local tables

Apparently GO statements are not supposed to be used so i've gone for the transaction approach (makes sense also - either it all happens or none of it happens):

Expand|Select|Wrap|Line Numbers
  1. Begin Transaction
  2.  
  3. truncate table arista_caclient
  4. truncate table arista_camatgrp
  5. truncate table arista_camatter
  6. truncate table arista_cabilhis
  7. truncate table arista_cablaloc
  8. truncate table arista_cafintrn
  9. truncate table arista_cadescrp
  10. truncate table arista_catimtrn
  11. truncate table arista_cafeextn
  12. truncate table arista_fmsaddr
  13. truncate table arista_cabilloi
  14. truncate table arista_caferate
  15.  
  16. INSERT INTO arista_caclient SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM caclient WHERE cl_datopn>=''01/01/1900'' OR cl_datopn is null')
  17. INSERT INTO arista_camatgrp SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM camatgrp WHERE (mg_datcls>=''01/01/1900'' OR mg_datcls is null) AND (mg_datopn>=''01/01/1900'' OR mg_datopn is null)')
  18. INSERT INTO arista_camatter SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM camatter WHERE (mt_estcmp>=''01/01/1900'' OR mt_estcmp is null)')
  19. INSERT INTO arista_cabilhis SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM cabilhis WHERE (bh_bildat>=''01/01/1900'' OR bh_bildat is null) AND (bh_laspay>=''01/01/1900'' OR bh_laspay is null) AND (bh_rundat>=''01/01/1900'' OR bh_rundat is null) AND (bh_remdat>=''01/01/1900'' OR bh_remdat is null)')
  20. INSERT INTO arista_cablaloc SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM cablaloc')
  21. INSERT INTO arista_cafintrn SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM cafintrn WHERE (tr_trdate>=''01/01/1900'' OR tr_trdate is null)')
  22. INSERT INTO arista_cadescrp SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM cadescrp')
  23. INSERT INTO arista_catimtrn SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM catimtrn WHERE (tt_trndat>=''01/01/1900'' OR tt_trndat is null)')
  24. INSERT INTO arista_cafeextn SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM cafeextn')
  25. INSERT INTO arista_fmsaddr SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM fmsaddr')
  26. INSERT INTO arista_cabilloi SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM cabilloi')
  27. INSERT INTO arista_caferate SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM caferate')
  28.  
  29. DBCC DBreindex (arista_caclient)
  30. DBCC DBreindex (arista_camatgrp)
  31. DBCC DBreindex (arista_camatter)
  32. DBCC DBreindex (arista_cablaloc)
  33. DBCC DBreindex (arista_catimtrn)
  34. DBCC DBreindex (arista_cafintrn)
  35. DBCC DBreindex (arista_cadescrp)
  36. DBCC DBreindex (arista_cafeextn)
  37. DBCC DBreindex (arista_fmsaddr)
  38. DBCC DBreindex (arista_cabilloi)
  39. DBCC DBreindex (arista_caferate)
  40.  
  41. If @@error <> 0
  42.     Rollback Transaction
  43. Commit Transaction
  44.  
Ideally i would like to insert a line into a seperate table if it succeeds or a line into a table if it fails. Would it be best to place that INSERT command before the Rollback and Commit statements?

Is this structured correctly?

Many thanks!
Oct 30 '07 #1
1 1774
iburyak
1,017 Recognized Expert Top Contributor
Try something like this for each table:

Expand|Select|Wrap|Line Numbers
  1. Begin Tran
  2. INSERT INTO arista_caclient SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM caclient WHERE cl_datopn>=''01/01/1900'' OR cl_datopn is null')
  3. If @@error <> 0
  4.   BEGIN
  5.     Rollback Tran
  6.     Insert into some table (status, date) values (‘Failed insert into arista_caclient’, getdate())
  7.   END
  8. ELSE
  9.   BEGIN
  10.     Commit Tran
  11.     Insert into some table (status, date) values (‘success inserting into arista_caclient’, getdate())
  12.  
  13.   END
  14.  
  15. Begin Tran
  16. INSERT INTO arista_camatgrp SELECT * FROM OPENQUERY(arista_ODBClink,'SELECT * FROM camatgrp WHERE (mg_datcls>=''01/01/1900'' OR mg_datcls is null) AND (mg_datopn>=''01/01/1900'' OR mg_datopn is null)')
  17. If @@error <> 0
  18.   BEGIN
  19.     Rollback Tran
  20.     Insert into some table (status, date) values (‘Failed insert into arista_camatgrp’, getdate())
  21. END
  22. Else 
  23.   BEGIN
  24.     Commit Tran
  25.     Insert into some table (status, date) values (‘success inserting into arista_camatgrp’, getdate())
  26.  
  27.   END

You had a problem because you didn’t commit after each table and if something happened you get nothing. Also your transaction log gets overloaded with uncommitted data which slows down your process.


Good Luck.
Nov 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
5
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
3
by: Richard Webb | last post by:
Hi all, I guess this is more of a design problem than a language problem, but I'm confused either way! I have a class and it has a private data member which is a struct. The size of the struct is...
6
by: jcrouse | last post by:
Here is a sniplet from a text file game name mapp description "Mappy (US) year 198 manufacturer "Namco history "\nMappy (c) 03/1983 Namco. \n\n- TRIVIA: \n\nLicensed to Bally Midway for US...
2
by: David Garamond | last post by:
I was thinking on how one would design an optimal (performance-wise) database of large number of schedules with crontab-like semantic. There will potentially be hundreds of thousands or even...
0
by: Brian Cole | last post by:
I'm profiling some code that screens a large database. The algorithm efficiency is heavily variable, based upon the different records in the database. In order to get a sense of the best place to...
3
by: The Frog | last post by:
Hi everyone, I am trying to refine some ADO code that is used to extract data from excel spreadsheets and do a simple ETL type process to place the data into a table. The code works fine and is...
3
by: tim999 | last post by:
Dear all, I have a question regarding indexes on a data extract database we have - MSSQL2000. Each night a scheduled job: 1. Deletes the indexes 2. Truncates the table data (empties the...
2
by: Aaron Watters | last post by:
Poking around I discovered somewhere someone saying that Python gc adds a 4-7% speed penalty. So since I was pretty sure I was not creating reference cycles in nucular I tried running the tests...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.