I have a SQL Server database with lot of tables (several hundrends), somehow related with each other. All of them have Primary Keys (GUID), but only few of them have actually defined Foreign Key constraints.
I need to find all tables related with certain table (let's call it TargetTable) both related directly and inderectly (through 1, 2 or more intermediate tables) on any column.
My finish goal to get SQL queries (one per each related table) which JOIN all tables between TargetTable and that related table.
For example: it's found 5 related to TargetTable tables:
- TargetTable - Table1
- TargetTable - Table1 - Table2
- TargetTable - Table3
- TargetTable - Table3 - Table4
- TargetTable - Table3 - Table4 - Table5
I need to get 5 separate JOINs.
It there any SQL query or software or utility or any way to get desired SQL codes? Or even enough to get relations in some convinient graph so i could parse them with my favourite script language and generate SQL codes.