Loading...
 
JoiWiki » Developer » Databases » SQL Scripts » SQL Show Unique Tables Between Databases SQL Show Unique Tables Between Databases

SQL Show Unique Tables Between Databases

It's exactly as you'd expect, a quick script to compare two databases and show the table names that are unique to each:

SELECT  *
FROM (  SELECT distinct  
            'Env1' env,
            o.name TableName
            FROM Database1.sys.objects o
            WHERE 1=1
            AND o.is_ms_shipped <> 1) CT
full join ( SELECT distinct  
            'Env2' env,
            o.name TableName
            FROM Database2.sys.objects o
            WHERE 1=1
            AND o.is_ms_shipped <> 1) D on CT.tablename = D.tablename
where (d.env is null or ct.env is null)
and LEFT(ISNULL(ct.tablename,'0'),2) <> 'DF'
and LEFT(ISNULL(D.tablename,'0'),2) <> 'DF'
and LEFT(ISNULL(ct.tablename,'0'),3) <> 'CTE'
and LEFT(ISNULL(D.tablename,'0'),3) <> 'CTE'

 

Created by JBaker. Last Modification: Tuesday September 24, 2019 11:51:49 BST by JBaker.

Developer