0

I want to get a list of all joins in all views in a SQL Server database.

I realise that I can get the view definition which will include the source for the join statement. But I want it expressed in a list form - something like: schema, view, join_sequence, column_sequence, table1_name, table1_col_name, table2_name, table2_col_name.

Anyone able to help?

I tried searching with Google to no avail.

Frank
  • 1
  • There's no such thing easily available. Closest is to check dependencies perhaps. My google search turned up this: https://learn.microsoft.com/en-us/sql/relational-databases/tables/view-the-dependencies-of-a-table?view=sql-server-ver16 combined with sys.objects and sys.columns – siggemannen Apr 18 '23 at 14:33
  • 1
    [Answer to similar question](https://stackoverflow.com/questions/75957293/option-in-scriptdom-to-retrieve-table-names-with-join-column-names/75959069#75959069). – Dan Guzman Apr 18 '23 at 14:35

1 Answers1

0

This query will show you every tables and views that are used in all of your views.

SELECT *
FROM INFORMATION_SCHEMA.VIEW_TABLE_USAGE

This doc may help you : Find SQL Server Views Where Table is used and List Tables in a View

Delta
  • 551
  • 2
  • 16