I have a table A that has primary key Id. I want to find all tables that contain this key as foreign. Number of tables is about 100, so its rather impossible to use generated database diagram. Is it any way to to query database schema objects to find it? Or maybe some other ways?
Asked
Active
Viewed 668 times
1
-
And you're sure that all of those 100 tables actually relate to `TableA`? – Yuck Feb 07 '12 at 13:28
-
sybase, oracle, sql server, etc.? – aF. Feb 07 '12 at 13:30
-
I would do this: Auto-Generate DB-Create-Skript. Search DB-Script for the ref-foreign-key-to-your-column syntax. – juergen d Feb 07 '12 at 13:31
-
No of course, the reason i asked is that i'm not sure which tables relate to it :) – idm Feb 07 '12 at 13:32
-
possible duplicate of [How to find foreign key dependencies in SQL Server?](http://stackoverflow.com/questions/925738/how-to-find-foreign-key-dependencies-in-sql-server) – aF. Feb 07 '12 at 13:33
-
The schema does not provide cascade-deletion and in some cases I want to reassign all related objects to another instance of A by hands without errors – idm Feb 07 '12 at 13:37
2 Answers
2
If we are talking about Sql Server Right Click on that table then View Dependecies
More info at :

Massimiliano Peluso
- 26,379
- 6
- 61
- 70
1
Try this:
SELECT *
FROM sys.foreign_keys
WHERE referenced_object_id = object_ID('dbo.TableA')
This finds all foreign keys that reference your TableA

marc_s
- 732,580
- 175
- 1,330
- 1,459