Example and Notes
Use this SQL Server example as a starting point for development, troubleshooting, reporting, or maintenance work. Review it against your schema, data volume, permissions, and SQL Server version before using it in production.
Sometimes you need to find all objects that reference or use a specific object. For example, you may want to find all the objects that use a specific table - such as a table called tlkTimeZone. This sample procedure will show you how to accomplish this.
Create Procedure uspGetObjectReferences
@prmReferencedObject varchar(250)
As
SELECT o2.name As ReferencedObject,
o1.name As UsedByObject
FROM sys.sql_expression_dependencies ed
INNER JOIN sys.objects o1 ON ed.referencing_id = o1.object_id
INNER JOIN sys.objects o2 ON ed.referenced_id = o2.object_id
Where o2.name = @prmReferencedObject
GO
Exec uspGetObjectReferences 'tlkTimeZone'
Production Review
WSI can adapt this script for your database, improve error handling, tune performance, document the logic, and help deploy it safely.