此解决方案只能部分回答您的问题。它不适用于作为表达式的列。
您可以使用sys.dm_exec_describe_first_result_set获取列信息:
@include_browse_information
如果设置为1,则将对每个查询进行分析,就像在查询中具有FOR BROWSE选项一样。返回其他键列和源表信息。
CREATE TABLE txu(id INT, first_name VARCHAr(10), last_name VARCHAr(10));CREATE TABLE txd(id INT, id_fk INT, address VARCHAr(100));CREATE VIEW v_txuASSELECt t.id AS PK_id, t.first_name AS name, d.address, t.first_name + t.last_name AS name_fullFROM txu tJOIN txd d ON t.id = d.id_fk
主要查询:
SELECt name, source_database, source_schema, source_table, source_column FROM sys.dm_exec_describe_first_result_set(N'SELECt * FROM v_txu', null, 1) ;
输出:
+-----------+--------------------+---------------+--------------+---------------+| name | source_database | source_schema | source_table | source_column |+-----------+--------------------+---------------+--------------+---------------+| PK_id | fiddle_0f9d47226c4 | dbo| txu | id || name | fiddle_0f9d47226c4 | dbo| txu | first_name || address | fiddle_0f9d47226c4 | dbo| txd | address || name_full | null | null | null | null |+-----------+--------------------+---------------+--------------+---------------+
DBFiddleDemo
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)