开发者

Query to get list of views that use a certain field in SQL Server

开发者 https://www.devze.com 2023-01-25 17:21 出处:网络
Does anybody know of a query from system tables or views to get a list of views that use 开发者_C百科a certain field in a SQL Server database?SELECT *

Does anybody know of a query from system tables or views to get a list of views that use 开发者_C百科a certain field in a SQL Server database?


SELECT *
FROM
    sys.sql_modules m
    JOIN
    sys.views v ON m.object_id = v.object_id
WHERE
    m.definition LIKE '%MyTable%' --or '%MyField%'

INFORMATION_SCHEMA views and legacy syscomments are unreliable for large view definition (or any definition) because they have nvarchar(4000) fields. sys.sql_modules uses nvarchar(max).

They should not be used

sys.sql_expression_dependencies may be an alternative but is more complex to use.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号