Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Check before insert or periodically delete dupes?

Author  Topic 

NewMedia42
Starting Member

35 Posts

Posted - 2009-02-27 : 23:13:55
I have two tasks that run and update the same table - the table gets about 6 million new records per day from the two processes.

Currently I check before each insert to verify that an item matching it doesn't already exist - this is true probably > 80% of the time.

My question is - would it be faster to just always insert (regardless if a match already exists, and just periodically run a task on the table to delete duplicates? This will obviously increase fragmentation, but is it worth exploring this? Looking through the profiler (code), it's spending 85% of it's time checking for pre-existing entries, so this would make a major speedup.

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-27 : 23:31:45
All three(update/delete/insert) deals with external and internal fragmentation.You might wanna try with SSIS with Lookup transformation Tasks.There are plenty of Examples in SSIS topic.
Go to Top of Page

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2009-03-06 : 09:22:54
You may be able to speed up the check for dupes. This link gives various methods to find / remove dupes.
http://www.simple-talk.com/sql/t-sql-programming/removing-duplicates-from-a-table-in-sql-server/

If a time-lag is acceptable you could do insert to a staging table, and periodically move new records to the final table and delete the rest. This would deal with the fragmentation problem.
Go to Top of Page
   

- Advertisement -