Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to get common Tables between 2 databases? Expand / Collapse
Author
Message
Posted Tuesday, December 18, 2012 1:20 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 18, 2013 4:14 AM
Points: 38, Visits: 198
Hello All,
I am sure some of the admin might have gone thorugh the same situation, I need a script that will give me common tables between 2 databases, we have 2 databases where 1 table has a entry in other and i am trying to merge these tables through export task which is failing coz the table names are already in there, so i was asked to come up with the names then we will decide if we need it or not. So please let me know how can we get the common tables across 2 databases.


Thanks in advance.....

Cheers...
Post #1397594
Posted Tuesday, December 18, 2012 2:17 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:29 AM
Points: 13,741, Visits: 10,716
An easy query:

SELECT name
FROM DB1.sys.[tables] t
WHERE [type] = 'U'
INTERSECT
SELECT name
FROM DB2.sys.[tables] t
WHERE [type] = 'U';

It doesn't take the schema into account.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1397614
Posted Tuesday, December 18, 2012 2:40 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 18, 2013 4:14 AM
Points: 38, Visits: 198
Thanks Koen...It worked...exactly what i needed ....
Post #1397624
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse