SQL Server 2008 view columns correspond to table columns

I am trying to write some SQL code that, when presenting a view, will find columns that will refer to the columns of the views, if they are in these columns. The ultimate goal is to provide users with a list of columns that could be used when requesting a view.

Currently, I can only find columns that the view uses (and by expanding their indexes), but I cannot match them with index columns.

For instance:

I have TableAthat has 5 columns: ID, Name, Val1, Val2,TableBID

I have TableBthat has 3 columns: ID, Name,Code

Then create a view View1that:

SELECT A.ID,
Name,
Val1
FROM TableA A
INNER JOIN TableB ON A.TableBID = B.ID
WHERE B.Code = 'AAA'

, :

SELECT *
FROM sys.dm_sql_referenced_entities('dbo.View1', 'OBJECT')

/ , , View Column , .

- , , , , , , .

SQL Server 2008 SP1, - .

+3
1

+ '_' + ColumnName . .

-1

Source: https://habr.com/ru/post/1741943/


All Articles