sp_depends (Transact-SQL)

Displays information about database object dependencies, such as: the views and procedures that depend on a table or view, and the tables and views that are depended on by the view or procedure. References to objects outside the current database are not reported.

Topic link iconTransact-SQL Syntax Conventions

Syntax

sp_depends [ @objname = ] '<object>' 

<object> ::=
{
    [ database_name. [ schema_name ] . | schema_name.
        object_name
}

Arguments

  • database_name
    Is the name of the database.
  • schema_name
    Is the name of the schema to which the object belongs.
  • object_name
    Is the database object to examine for dependencies. The object can be a table, view, stored procedure, user-defined function, or trigger. object_name is nvarchar(776), with no default.

Return Code Values

0 (success) or 1 (failure)

Result Sets

sp_depends displays two result sets.

The following result set shows the objects on which <object> depends.

Column name Data type Description

name

nvarchar(257)

Name of the item for which a dependency exists.

type

nvarchar(16)

Type of the item.

updated

nvarchar(7)

Whether the item is updated.

selected

nvarchar(8)

Whether the item is used in a SELECT statement.

column

sysname

Column or parameter on which the dependency exists.

The following result set shows the objects that depend on <object>.

Column name Data type Description

name

nvarchar(257)

Name of the item for which a dependency exists.

type

nvarchar(16)

Type of the item.

Remarks

An object that references another object is considered dependent on that object. sp_depends determines the dependencies by looking at the sys.sql_dependencies catalog view.

Permissions

Requires membership in the public role.

Examples

A. Listing dependencies on a table

The following example lists the database objects that depend on the Sales.Customer table in the AdventureWorks database. Both the schema name and table name are specified.

USE AdventureWorks
GO
EXEC sp_depends @objname = N'Sales.Customer' ;

Here is the result set.

In the current database, the specified object references the following:
Name                  type             updated   selected  column
----------------------------------------------------------------
Dbo.ufnLeadingZeros   scalar function  no        no        NULL
Sales.Customer        user table       no        no        CustomerID

In the current database, the specified object is referenced by the following:
name                            type
------------------------------- ---------------- 
Sales.CK_Customer_CustomerType  check cns
Sales.Customer                  user table
Sales.vIndividualCustomer       view
Sales.vStoreWithDemographics    view

B. Listing dependencies on a trigger

The following example lists the database objects on which the trigger iWorkOrder depends.

EXEC sp_depends @objname = N'AdventureWorks.Production.iWorkOrder' ;

See Also

Reference

Database Engine Stored Procedures (Transact-SQL)
EXECUTE (Transact-SQL)
sp_help (Transact-SQL)
System Stored Procedures (Transact-SQL)
sys.sql_dependencies (Transact-SQL)

Other Resources

Understanding SQL Dependencies

Help and Information

Getting SQL Server 2005 Assistance