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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 big table lookup

Author  Topic 

subhaoviya
Posting Yak Master

135 Posts

Posted - 2014-05-20 : 07:07:16
Hi,
I am having main table T1 having 50 million records init, having another table t2 having 3000 records.
T1:
C1, C2, C3, c4, c5

T2:
C1, C2

I need to match C1 between both tables and if matched need to update C2 else need to insert record into T1. Even when I used merge statement for this due to heavy data collection in T1. query taking more than 3 hours to execute.


not only this T2 I have having 6 more tables having some thousand of records to match with T1 and update other columns init.

please help me to optimise this action.

Thanks
Subha



bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2014-05-20 : 07:34:54
While executing the MERGE, enable execution plan (Ctrl + M). Have a look at the index usage and which one is costliest operation..

NOTE: Find out any Missing Indexes on those tables

--
Chandu
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2014-05-20 : 17:03:20
Best for this process would be for T1 to be clustered on C1; can't say overall if that is best for the table.

MERGE often has performance issues. You'd almost certainly be better off doing an UPDATE followed by an INSERT.
Go to Top of Page
   

- Advertisement -