When you need to understand how a SQL Server or Azure SQL database uses a table, one common task is finding the stored procedures that reference it. This is useful before changing a table, troubleshooting dependencies, reviewing legacy code, or planning a database migration.

Quick answer: For reliable dependency information, use SQL Server dependency metadata such as sys.sql_expression_dependencies or sys.dm_sql_referencing_entities. Searching sys.sql_modules with LIKE is also useful as a text search, but it can produce false positives and can miss references that are resolved dynamically.

Find stored procedures that reference a table

Microsoft recommends dependency metadata for identifying objects that reference a table. The following query lists referencing objects for a specific table and filters the result to Transact-SQL stored procedures.

DECLARE @TableName nvarchar(517) = N'dbo.YourTable';

SELECT
    OBJECT_SCHEMA_NAME(sed.referencing_id) AS referencing_schema,
    OBJECT_NAME(sed.referencing_id) AS stored_procedure,
    o.type_desc AS object_type
FROM sys.sql_expression_dependencies AS sed
INNER JOIN sys.objects AS o
    ON sed.referencing_id = o.object_id
WHERE sed.referenced_id = OBJECT_ID(@TableName)
  AND o.type = 'P'
ORDER BY
    referencing_schema,
    stored_procedure;

Replace dbo.YourTable with the schema-qualified table name you want to investigate. This approach uses dependency information maintained by SQL Server rather than simply searching procedure text.

Use sys.dm_sql_referencing_entities

You can also ask SQL Server for the entities in the current database that reference a specific table:

SELECT
    referencing_schema_name,
    referencing_entity_name,
    referencing_id,
    referencing_class_desc,
    is_caller_dependent
FROM sys.dm_sql_referencing_entities(
    N'dbo.YourTable',
    N'OBJECT'
)
WHERE referencing_class_desc = N'OBJECT'
  AND OBJECTPROPERTYEX(referencing_id, 'IsProcedure') = 1
ORDER BY
    referencing_schema_name,
    referencing_entity_name;

sys.dm_sql_referencing_entities returns entities in the current database that reference the specified user-defined entity by name. Microsoft documents support for SQL Server, Azure SQL Database, Azure SQL Managed Instance, and SQL database in Microsoft Fabric.

Search stored procedure definitions with sys.sql_modules

If you specifically want a text search through stored procedure definitions, sys.sql_modules can be useful:

SELECT
    SCHEMA_NAME(o.schema_id) AS schema_name,
    o.name AS stored_procedure
FROM sys.objects AS o
INNER JOIN sys.sql_modules AS m
    ON o.object_id = m.object_id
WHERE o.type = 'P'
  AND m.definition LIKE N'%YourTable%'
ORDER BY
    schema_name,
    stored_procedure;

This is a simple way to search procedure text, but it should not be treated as a complete dependency analysis. The table name can appear in comments or string literals, and references constructed dynamically may not be represented in the procedure definition in a way that a simple text search can identify.

Find all objects that depend on a table

If you are assessing the impact of changing a table, you may want to find views, stored procedures, functions, and other database objects rather than procedures only.

SELECT
    OBJECT_SCHEMA_NAME(sed.referencing_id) AS referencing_schema,
    OBJECT_NAME(sed.referencing_id) AS referencing_object,
    o.type_desc AS object_type
FROM sys.sql_expression_dependencies AS sed
LEFT JOIN sys.objects AS o
    ON sed.referencing_id = o.object_id
WHERE sed.referenced_id = OBJECT_ID(N'dbo.YourTable')
ORDER BY
    object_type,
    referencing_schema,
    referencing_object;

SQL Server Management Studio: View table dependencies

In SQL Server Management Studio (SSMS), you can also inspect dependencies from Object Explorer. Expand the database and Tables, right-click the table, and select View Dependencies. In the Object Dependencies dialog, select Objects that depend on <object name>. Stored procedures appear in the dependency results when they are tracked as dependencies.

Important limitations

  • Use a schema-qualified name: Prefer dbo.YourTable rather than only the table name.
  • Dependency metadata is preferable to LIKE: Use sys.sql_expression_dependencies or the dependency DMF when you need dependency information rather than a text search.
  • Review dynamic SQL separately: References assembled and executed dynamically may not be captured as normal dependency relationships.
  • Check permissions: Visibility of dependency information can depend on permissions such as VIEW DEFINITION.
  • Cross-database references need extra attention: dependency metadata can contain database and schema information for references outside the current database, but a simple OBJECT_ID() lookup is scoped to the current database.

Available on Microsoft Store

SSRS Reports Migration Wizard

A simple Windows tool for migrating SSRS reports, data sources, and related configurations between report servers.

Related SQL Server topic: When dependency analysis is part of a larger maintenance or migration task, see Transaction Batching in SQL Server for safer processing of large update and delete operations.

Conclusion

For finding stored procedures related to a table, start with SQL Server’s dependency metadata instead of relying only on a text search. sys.sql_expression_dependencies and sys.dm_sql_referencing_entities provide a more structured way to identify referencing objects, while sys.sql_modules remains useful when you need to search procedure definitions directly.

See more

Visual Studio Marketplace

SSIS Catalog Migration Wizard

Extend Visual Studio with an easy way to migrate SSIS Catalog projects.

Pro tips:
1. Learn how to grant access to Azure SQL database.

Kunal Rathi

With over 15 years of experience in data engineering and analytics, I've assisted countless clients in gaining valuable insights from their data. As a dedicated supporter of Data, Cloud and DevOps, I'm excited to connect with individuals who share my passion for this field. If my work resonates with you, we can talk and collaborate.