Reputation: 979
In order to identify high risk views when making changes to underlying tables and be able to do sp_refreshview
, I'd like to get the names of all views that are querying all (*) the columns from a table using the SELECT *
For example, find views with cases like:
SELECT *
SELECT SomeAlias.*
Note:
I understand that SELECT *
is a bad practice and strongly not recommended
Upvotes: 1
Views: 68
Reputation: 979
This is how I did it:
SELECT DISTINCT
o.name AS ObjectName,
o.type_desc ObjectType,
SUBSTRING (m.definition, PATINDEX ( '%[.][*]%' , m.definition )-4, 20) MatchedPattern
FROM sys.sql_modules m
INNER JOIN
sys.objects o
ON m.object_id = o.object_id
WHERE m.definition Like '%[.][*]%'
AND o.type_desc IN ('VIEW')
Upvotes: 1