SELECT t1.name AS list1,
t2.name AS list2,
count(distinct c2.name) AS commonColumns
FROM sys.tables t1
CROSS JOIN sys.tables t2
INNER JOIN sys.columns c1 ON c1.object_id = t1.object_id
LEFT OUTER JOIN sys.columns c2 ON c2.object_id = t2.object_id AND c1.name=c2.name
GROUP BY t1.name,t2.name
ORDER BY t1.name,t2.name
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537