【发布时间】:2011-03-10 02:06:08
【问题描述】:
我在 Sybase 数据库中有 500 个存储过程。使用 SQL,我可以获得使用特定表的所有存储过程的列表,例如 tbl_books?
【问题讨论】:
我在 Sybase 数据库中有 500 个存储过程。使用 SQL,我可以获得使用特定表的所有存储过程的列表,例如 tbl_books?
【问题讨论】:
使用这样的东西:
Select distinct sysobjects.name
, case
when sysobjects.type = 'TR' then 'TRIGGER'
when sysobjects.type = 'P' then 'PROCEDURE'
when sysobjects.type = 'V' then 'VIEW'
else 'UNKNOWN' end type
from sysobjects inner join syscomments
on sysobjects.id = syscomments.id
where syscomments.text like '%tbl_books%'
【讨论】:
最初我会尝试sp_depends。
Syntax: sp_depends objname[, column_name]
对于objname,您可以提供任何对象名称,例如表、视图或存储过程。
【讨论】:
sp_depends相反的功能。
如果有另一个表名说,像这样使用 syscmets 将停止工作 tbl_books_new。更好的方法是使用 sysdepends
select so1.name from
sysobjects so1, sysobjects so2, sysdepends sd
where so1.id = sd.id
and so2.id = sd.depid
and so2.name = 'tbl_books'
and so1.type = 'P'
【讨论】:
这样的事情怎么样:
select proc_name from sysprocedures where proc_defn like "%tbl_books%"
【讨论】:
请记住,syscmets 中的文本列是 varchar(255),因此一个大程序可以由 syscmets 中的多行组成,因此,如果您正在搜索的表名,上述选择将找不到程序名,已在 syscmets 中拆分为 2 个文本行。
我建议使用以下选择,它将处理上述情况:
declare @text varchar(100)
select @text = "%tbl_books%"
select distinct o.name object
from sysobjects o,
syscomments c
where o.id=c.id
and o.type='P'
and (c.text like @text
or exists(
select 1 from syscomments c2
where c.id=c2.id
and c.colid+1=c2.colid
and right(c.text,100)+ substring(c2.text, 1, 100) like @text
)
)
order by 1
-- 感谢ASEisql的创建者
【讨论】: