Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to script all objects which depend on a SQL Server table

The 'View Dependecies' shows all the objects which depend on a table in SQL Server. Now how do I use SSMS to script all these objects in one command? Is there a free tool that does this?

like image 660
Tony_Henrich Avatar asked Oct 22 '25 01:10

Tony_Henrich


1 Answers

First you can try this link Understanding SQL Dependencies

Second, you have multiple options to check the Dependencies

using sql_expression_dependencies table, to see the dependency of X on Y, run the following query.

SELECT * 
FROM sys.sql_expression_dependencies 
WHERE referencing_id = OBJECT_ID('X')
    AND referenced_id = OBJECT_ID('Y')
    AND referenced_schema_name = 'dbo'
    AND referenced_entity_name = 'Y'
    AND referenced_database_name IS NULL
    AND referenced_server_name IS NULL;

using the syscomments table, SQL Server's syscomments table stores the original SQL definition statement for every view, rule, default, trigger, CHECK and DEFAULT constraint, and stored procedure in your database. That's a lot of information! You can query this table to list dependent objects using a SQL statement in the following form

SELECT *
FROM syscomments 
INNER JOIN sysobjects sysobj ON syscomments.id = sysobj.id
WHERE charindex('your object to check', text) > 0 

using the sp_depends stored procedure, wich 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

EXEC sp_depends @objname = N'your object to check'
like image 96
RRUZ Avatar answered Oct 23 '25 20:10

RRUZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!