Returns one row for each entity in the current database that references another user-defined entity by name. A dependency between two entities is created when one entity, called the referenced entity, appears by name in a persisted SQL expression of another entity, called the referencing entity. For example, if a user-defined type (UDT) is specified as the referenced entity, this function returns each user-defined entity that reference that type by name in its definition. The function does not return entities in other databases that may reference the specified entity. This function must be executed in the context of the master database to return a server-level DDL trigger as a referencing entity.
You can use this dynamic management function to report on the following types of entities in the current database that reference the specified entity:
Schema-bound or non-schema-bound entities
Database-level DDL triggers
Server-level DDL triggers
Schema in which the referencing entity belongs. Is nullable.
NULL for database-level and server-level DDL triggers.
Name of the referencing entity. Is not nullable.
ID of the referencing entity. Is not nullable.
Class of the referencing entity. Is not nullable.
1 = Object
12 = Database-level DDL trigger
13 = Server-level DDL trigger
Description of class of referencing entity.
Indicates the resolution of the referenced entity ID occurs at run time because it depends on the schema of the caller.
1 = The referencing entity has the potential to reference the entity; however, resolution of the referenced entity ID is caller dependent and cannot be determined. This occurs only for non-schema-bound references to a stored procedure, extended stored procedure, or user-defined function called in an EXECUTE statement.
0 = Referenced entity is not caller dependent.
Returns an empty result set under any of the following conditions:
A system object is specified.
The specified entity does not exist in the current database.
The specified entity does not reference any entities.
An invalid parameter is passed.
Returns an error when the specified referenced entity is a numbered stored procedure.
The following table lists the types of entities for which dependency information is created and maintained. Dependency information is not created or maintained for rules, defaults, temporary tables, temporary stored procedures, or system objects.
Transact-SQL stored procedure**
CLR stored procedure
Transact-SQL user-defined function
CLR user-defined function
CLR trigger (DML and DDL)
Transact-SQL DML trigger
Transact-SQL database-level DDL trigger
Transact-SQL server-level DDL trigger
Extended stored procedures
Type (alias and CLR user-defined type)
XML schema collection
* A table is tracked as a referencing entity only when it references a Transact-SQL module, user-defined type, or XML schema collection in the definition of a computed column, CHECK constraint, or DEFAULT constraint.
** Numbered stored procedures with an integer value greater than 1 are not tracked as either a referencing or referenced entity.
For more information, see Understanding SQL Dependencies.
A. Returning the entities that refer to a given entity
The following example returns the entities in the current database that refer to the specified table.
B. Returning the entities that refer to a given type
The following example returns the entities that reference the alias type dbo.Flag. The result set shows that two stored procedures use this type. The dbo.Flag type is also used in the definition of several columns in the HumanResources.Employee table; however, because the type is not in the definition of a computed column, CHECK constraint, or DEFAULT constraint in the table, no rows are returned for the HumanResources.Employee table.
Here is the result set.
referencing_schema_name referencing_entity_name referencing_id referencing_class_desc is_caller_dependent
----------------------- ------------------------- ------------- ---------------------- -------------------
HumanResources uspUpdateEmployeeHireInfo 1803153469 OBJECT_OR_COLUMN 0
HumanResources uspUpdateEmployeeLogin 1819153526 OBJECT_OR_COLUMN 0
(2 row(s) affected)