If I have a table, TableA:
Id
1
2
3
...
And two other tables:
TableB:
Id, TableAId
1 1
2 1
TableC:
Id, TableAId
1, 1
2, 2
Where TableAId is a FK relationship with TableA.Id.
How do I determine that TableA, Id 1, has three rows pointing to it? And that TableA, Id 2 has one row pointing to it? And more specifically, how do I identify what those rows are? (their table name and Id)
You can use the
INFORMATION_SCHEMAviews to generate select statements to display the rows in question. I have only tested this against the tables provided in the question, but it could be expanded to work in cases where the keys are multiple columns.The select statements generated:
and the query results: