Determining the dependencies of a stored procedure.

假如想象 提交于 2020-01-06 04:29:46

问题


Is there a way (or, ideally, a query) to determine all the tables that a stored procedure accesses, including those accessed by other stored procs that it calls itself (and those that they call, etc. down the call stack).

If anyone can fabricate such a query, is it additionally possible to determine whether tables are accessed for update, select or delete?

Is it possible to determine the same where views are thrown into the mix?

My stored procs do not contain any dynamically-constructed calls, so that simplifies it at least slightly.


回答1:


Try this Link:

how-to-find-all-dependencies-of-a-table-in-sql-server

or this to search text:

DECLARE @Search varchar(255)
SET @Search='cost_centre'
SELECT DISTINCT
    o.name AS Object_Name,o.type_desc
    FROM sys.sql_modules        m 
        INNER JOIN sys.objects  o ON m.object_id=o.object_id
    WHERE m.definition Like '%'+@Search+'%'
    ORDER BY 2,1



回答2:


i've got no access to sql-server at the moment, but i know you can check dependecies - i've done this, determining views accessing tables.

have a look at sys.all_objects and sysdepends. you can join them on object_id and depid. including the type-column of sysdepends, you should be able to get the tables, accessed by a SP.

will have a look tomorrow, if still neccessary - but you should be able to get your information checking the above infos!

@edit: just saw comment of Aaron. Everything explained right there. Perhaps it was luck to get the right dependencies in my case ;)



来源:https://stackoverflow.com/questions/13631177/determining-the-dependencies-of-a-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!