Sybase:使用特定表获取存储过程列表

时间:2010-06-30 11:21:28

标签: stored-procedures sybase

我在Sybase数据库中有500个存储过程。使用SQL,我是否可以获得使用特定表的所有存储过程的列表tbl_books

5 个答案:

答案 0 :(得分:23)

使用类似的东西:

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%'

答案 1 :(得分:3)

最初我会尝试sp_depends

Syntax: sp_depends objname[, column_name]

对于objname,您可以提供任何对象名称,例如表格,视图或图表。

答案 2 :(得分:2)

如果有另一个表名,那么使用类似的syscomments将停止工作 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'

答案 3 :(得分:0)

如何处理以下内容:

select proc_name from sysprocedures where proc_defn like "%tbl_books%"

答案 4 :(得分:0)

请记住,syscomments中的text列是varchar(255),因此一个大的过程可以包含syscomments中的多行,因此,如果你要搜索的是表名,上面的选择将找不到过程名,已在syscomments中拆分为2个文本行。

我建议使用以下select,它将处理上述情况:

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

的创造者