查询存储过程 视图调用关系

ALTER proc [op].[uspGetDepends](
@StrName varchar(100),
@Type varchar(10) = 'all'
)
as
begin
set nocount on
--查询非用户表,即函数、存储过程、视图、约束等等。
select schema_name(schema_id) as [schema],*
from sys.objects
where object_id in(
select id from syscomments
where [text] like '%'+@StrName+'%'
and patindex('%201[0-9]%',[name]) = 0 --排除名字中包含年份的备份数据库对象
) and (@type = 'all' or [type] = @type)

union all
--查询用户自定表。
select schema_name(schema_id) as [schema],*
from sys.objects
where [name] like '%'+@StrName+'%'
and patindex('%201[0-9]%',[name]) = 0 --排除名字中包含年份的备份数据库对象
and [type] ='U' and ( @type='all' or @type = 'U')

order by [name]
set nocount off
end

原文地址:https://www.cnblogs.com/shuai0147/p/7728346.html