SQL Server: ways to compare data between large tables and view

Need to compare data between large tables and views. Databases are on different servers.  One has tables, the other has views derived from the 3rd database on the same server.
EXCEPT on original tables and views takes forever.

Thank you in advance.
quasar_eeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim P.Commented:
Is it just the primay key(s) or is it deeper in?

For just a PK you can use left joins. For example:
SELECT srvr1.PK, srvr2.PK, srvr1.fld1, srvr1.fld2, srvr1.fld3 ....
FROM [Svr1\Instance].[DBName].dbo.TblName srvr1
LEFT  JOIN [Svr2\Instance].[DBName].dbo.TblName srvr2
     ON srvr1.PK = srvr2.PK
WHERE srvr2.PK is null /**  or is not null  **/

Open in new window


If you want to check specific fields then add it in the ON clause.
SELECT srvr1.PK, srvr2.PK, srvr1.fld1, srvr1.fld2, srvr1.fld3 ....
FROM [Svr1\Instance].[DBName].dbo.TblName srvr1
LEFT  JOIN [Svr2\Instance].[DBName].dbo.TblName srvr2
     ON srvr1.PK = srvr2.PK
     AND srvr1.fld1= srvr2.fld1
WHERE srvr2.PK is null /**  or is not null  **/
AND      srvr2.fld1 is null  /**  or is not null  **/

Open in new window

0
Vikas GargBusiness Intelligence DeveloperCommented:
HI,

You can use EXISTS

Select * from Table1 b where srvr1.PK not exists (select srvr2.PK from view a where a.srvr2.PK=b.srvr1.PK)

Open in new window


Which will give you the records which are in table but not in view

Same way you can find records which are in view but not in Table

Hope this would help
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David ToddSenior DBACommented:
Hi,

Would Red Gate Data compared be easier to use/better performance?

HTH
  David
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.