Solved

Use DTS in VB6 EXE to transfer data when some records already in Table (PK Voilation)

Posted on 2004-09-29
10
302 Views
Last Modified: 2011-10-03
Hi

I've coded an EXE which opens an ADO connection to various OLEDB/ODBC data sources and transfers the records, depending on the SQL statement used record at a time into a SQL server database.

Problem is, its very slow!

A typical example of the SQL used is, "SELECT * WHERE rowDate = TODAY", and this statement will be executed every half hour so that the table is populated Intra-Day.

We've executed DTS packages to do the same thing and have noticed the significant speed advantages you can get with DTS, problem is, the DTS job is successful the first time, but will always error out the second time as some records are already in the database (and we need them to update every half hour).

Deleting and re-importing isnt an option, some of the tables are huge and we just get SQL Timeouts (even at 300 seconds).

Is there a way to use DTS to transfer the data and ignore the records with a Primary Key violation (ie duplicates)?

Or can we say do an insert into SQL Database where Unique identifer not in table?  Ie. SELECT * FROM (database A) where ID not in (Database B)? However I cant see how this will work as all the datasources are completely different and none of the primary keys will be the same.

Any help would be greatly appreciated.!

Thanks experts!
Matt
0
Comment
Question by:razorhazor
10 Comments
 
LVL 6

Expert Comment

by:mcp111
ID: 12183455
Use an Activexscript
check for id in the destination table
If dtsdestination("id") exists
set the dtstransformstat_skipinsert flag to skip inserting that row.
0
 
LVL 34

Expert Comment

by:arbert
ID: 12184090
You wouldn't even have to use ActiveX script.  Code ExecuteSQL statements that use INSERT/UPDATE queries based upon the key already existing in the table .
0
 
LVL 34

Expert Comment

by:arbert
ID: 12184103
Several different ways you could do it--to just find not existing records:

SELECT * WHERE rowDate = TODAY"
and yourkey not exist in (select 1 from yourtable table1 inner join yourtable  table2 where table1.primarykey=table2.primarykey)
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 5

Expert Comment

by:MichaelSFuller
ID: 12186946
For each table transformation implement this type of sql statement replacing the Composite Members with your primary key combination.
 
Select <unnull-column>,... from TableA left outer join TableB
on A.CompositeMember1= B.CompositeMember1 and
on A.CompositeMember2= B.CompositeMember2 and
on A.CompositeMember3= B.CompositeMember3 where
<unnull-column> is Null

This should alleviate your problems unless the primary keys are duplicated from source to source. If this is the case add a column to table to specify the source. Then when you are transforming your information into the destination table, set the source using an alias such as select 1 as iSource, ...from...table name.

Late,
0
 

Author Comment

by:razorhazor
ID: 12187783
Hi guys,

thanks for that, problem with joins though is that the data would be in seperate databases on seperate servers so I wouldnt have thought I would be able to code that in the same SQL statement?

Are we suggesting that I put the data into a temp table to begin with, then run the SQL statement to see whats not there?

Any chance of some example code to get my head round it?!?

Thanks for all your help
Matt
0
 
LVL 34

Accepted Solution

by:
arbert earned 250 total points
ID: 12189641
You can code the join (either via linked server or openrowset), but you need to check the query plan to see if the performance is good enough.
0
 
LVL 5

Assisted Solution

by:MichaelSFuller
MichaelSFuller earned 250 total points
ID: 12189867
Example:

(Select <unnull-column>,... from Table) as A left outer join
(SELECT a.*
FROM OPENROWSET('SQLOLEDB','Servername';'username';'password',
'SELECT * FROM TableB'))
AS B
on A.CompositeMember1= B.CompositeMember1 and
on A.CompositeMember2= B.CompositeMember2 and
on A.CompositeMember3= B.CompositeMember3 where
A.<unnull-column> is Null

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now