You can use the output of this script to analyze how a database object and even a specific column are used in the database. The results of this script are similar to the View Dependencies feature of SQL Server Management Studio. This script can be useful when making schema changes by helping you understand the scope and potential impact of those changes.
This script uses a few of SQL Server’s dynamic management views and functions. Part of the body of this script borrows from examples in Microsoft SQL Server Books Online (BOL).
The permissions required to use these views and functions will likely be granted to someone making DDL changes. (They include VIEW DEFINITION and CONTROL permissions. See BOL for the specific permissions required.) In the event that the account you run this script as doesn’t have the required permissions, one or more result sets may be empty.
To use the script, enter values for @SchemaQualifiedObjectName and (optionally) for @ColumnName, and execute it against a target database.