English 中文(简体)
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?

问题回答

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 

SSMS relyies on SMO to extract the dependencies. The DependencyWalker class, namely. You can wrap this in your code, and the SMO also has the posibility to script out object definitions using the Scripter class (which again is what SSMS uses to script object definitions too).





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签