Last Updated: February 25, 2016
·
306
· mwgriffith

SQL to search stored procedures if a specific table and column are used.

select OBJECT_NAME( sd.[object_id] ) As ObjectName, OBJECT_NAME( ac.[object_id] ) As DependentTableName
  , ac.[Name] As DependentColumnName
from sys.sql_dependencies sd
JOIN sys.all_columns ac ON sd.[referenced_major_id] = ac.[object_id]
                                AND sd.[referenced_minor_id] = ac.[column_id]
JOIN sys.objects so ON sd.[object_id] = so.[object_id]
WHERE so.[type] = 'P'
  AND OBJECT_NAME( ac.[object_id] ) = 'tablename'           --Tablename
  AND ac.name = 'field'                                                       -- column name