SQL Server Code Example

Get Object References for an Object

A practical SQL Server and Azure SQL code example for Get Object References for an Object.

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.

Readable Example

The original sample is preserved and presented in a cleaner professional layout.

Practical Context

Each example is framed around how it may be used in real SQL Server work.

Expert Support

WSI can adapt examples for your specific schema, business rules, and performance needs.

About Us

WSI is a small business and a leading provider of custom SQL Server/Azure programming and database solutions for government entities, Fortune 1000 companies, and emerging businesses. We are your custom SQL Server/Azure development experts.

Privacy Notice

We use essential cookies to make this site work. With your permission, we may also use analytics or marketing cookies.