Can I find all possible joins in one schema? For example up to level 2, 3 and 4.
I can do something like this:
*;with combination as (
select distinct rn = DENSE_RANK() over (order by table_name), table_name from INFORMATION_SCHEMA.TABLES
)
select
combination_no = ROW_NUMBER() Over (Order By NEWID()),
c1.table_name, c2.table_name, c3.table_name, c4.TABLE_NAME
from combination c1, combination c2, combination c3, combination c4
where
c1.rn < c2.rn and
c2.rn < c3.rn and
c3.rn < c4.rn
order by c1.rn, c2.rn, c3.rn, c4.rn
But, it's not what I meant. Can I generate these results only where there are connections?