I have one Employee table in my Database which has relations to different other tables. In my application, When a user try to delete one employee which has relational data in other tables, I want to display a list of that tables to the user. Can I list all table names which prevents the Employee to be deleted (relational data Tables) using a query?
Asked
Active
Viewed 446 times
1
-
1You can do with sys tables (check this http://stackoverflow.com/questions/8094156/know-relationships-between-all-the-tables-of-database-in-sql-server ), but in realtime that can be performance botteneck. I would suggest to return this list manually or let exception thrown having proper rollback mechanism. – Anil May 07 '15 at 06:40
1 Answers
2
Assuming there are foreign keys set up, you should be able to run this stored procedure.
EXEC sp_fkeys 'Employee'

TeamTam
- 1,598
- 11
- 15