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.
| Author |
Topic |
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2011-03-03 : 08:42:58
|
| I used SP below to compare two tables in Remote and Local SQL server(linked server) and select the deference.This is a daily job. There are about 300,000 records in Remote. Most time about 1000 deference records will insert into Local table.How to improve the code? (ID in both tables is primary key)ALTER PROCEDURE spCompareASBEGINSET nocount ON;BEGINCREATE TABLE #a(id INTCONSTRAINT pk_id PRIMARY KEY (id))INSERT INTO #a(id)SELECTidFROM[remote].[order_remote].dbo.order aWHERE NOT EXISTS(SELECTidFROMorder_local.dbo.order bWHERE b.id = a.id)ENDSELECTx.*FROM[remote].[order_remote].dbo.order xINNER JOIN #aON x.id = #a.idEND |
|
|
chtummala
Starting Member
4 Posts |
Posted - 2011-03-03 : 13:09:41
|
| select x.* from [remote].[order_remote].dbo.order xleft outer join order_local.dbo.order bon x.ID=b.IDwhere b.id is nullchandu |
 |
|
|
|
|
|