How do I find every view and function that uses a specific column in SQL Server?
23:31 10 Jun 2026

I'm working on an old SQL Server database where the main table has columns with generic names like MSTFLG01, MSTFLG02, all the way up to MSTFLG67. The actual meaning of each column is hidden inside views and functions that rename it to something readable. So MSTFLG14 might appear as CLAW_CURRENT_SUBTYPE in one view, and there's also a function called fn_CurrentSubtype that uses it.

To work out what a column means, I've been running this:

SELECT
    o.type_desc,
    o.name,
    m.definition
FROM sys.sql_modules m
JOIN sys.objects o ON o.object_id = m.object_id
WHERE m.definition LIKE '%MSTFLG14%'

It works, but I keep running into problems.

First, if I search for MSTFLG1, I also get back MSTFLG10, MSTFLG11 and so on. Not what I want.

Second, it only tells me the column name is somewhere in the text. I still have to open each result and read through it to find the alias.

Third, I can't tell the difference between a view that reads the column directly from the base table and a view that just selects from another view that reads it.

I had a look at sys.dm_sql_referenced_entities and sys.sql_expression_dependencies but they don't go down to the column level when views use SELECT * or sit on top of other views.

Is there a cleaner way to do this? Ideally I want a list of every view or function that uses a given column, what alias it gets renamed to, and whether it reads the base table directly or through another view.

Running SQL Server 2019. About 90 tables and 200 views in scope.

database database-design ssms legacy-database