-1

Hi there I'm knew to SQL and I'm facing what I hope is a basic problem.

Scenario: Say I have 2 tables, let these be Client and Reading. I want to find the table k which holds a relationship to both of them, so that I may perform an inner join to link Client to Reading.

Question: Does a query exist to find table k?

p.s.Client and Reading have many attributes which makes finding a relationship by hand very tedious.

TimTam
  • 41
  • 1
  • 8
  • Can you clarify on "a table having a relationship to another table"? – DVT Aug 03 '17 at 12:13
  • Look for foreign keys. – jarlh Aug 03 '17 at 12:13
  • The answer on [this](https://stackoverflow.com/questions/925738/how-to-find-foreign-key-dependencies-in-sql-server) thread will give you information on all tables that hold foreign key relationships to other tables as well as the foreign key information. Maybe this could somehow help you achieve what you need. – Rigerta Aug 03 '17 at 12:16
  • If you are using SSMS, it would be faster to simply use it to look at the keys. – Dan Bracuk Aug 03 '17 at 12:25

1 Answers1

2

If the tables have foreign keys, then yes you can query the meta tables to find the tables that have relationships to them.

If not, then no, there is no way to find them programmatically.

Tab Alleman
  • 31,483
  • 7
  • 36
  • 52