Goal:
Display detailed information if database A use database B:s table and its column. if yes, the list will display what is the name of the database B:s table and column that is being used in database A.
Purpose:
Database A has about 200 View and 400 tables and database B has about 154 View and 165 tables and I don't wanna review each table and view in order to locate what table and column it use from database B. The main purpose is to reduce the time.
Problem:
I do not know how to do it?
Information:
*I'm using SQL server 2008 R2
Best Answer
The catalog view
sys.sql_expression_dependencies
gets you close. For example:It does not provide column names, however.
Unfortunately other catalog views like
sql_dependencies
are unreliable for this kind of thing, since they don't follow dependencies outside the scope of the current database. And it's deprecated anyway. However there are more reliable views, likesys.dm_sql_referenced_entities
:Some other links that might help:
Also understand that dependencies are hard, they've changed the approach several times since SQL Server 2000, and we've had a long history of employing workarounds to ensure that the information is current and consistent (but still tend to fail on a regular basis).