I'm in a Data Warehouse environment where tables are generated by stored procedures, the stored procedures reference other tables, and those referenced tables are created by other stored procedures, and so on etc. I'd like to, for a given procedure or table, be able to trace back all the way to the source tables, effectively constructing a dependency chain for the given object.
I can use sys.dm_sql_referenced_entities
for procedures and sys.dm_sql_referencing_entities
for tables but these only reveal the first link in the chain. Presumably this is some kind of recursive query that stops when it finds no more dependencies? Has anyone done this before and can share how to do it?
Thank you.