Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sybase: get list of stored procedures using a particular table

I have 500 stored procedures in a Sybase database. Using SQL, can I get list of all stored procedures that are using a particular table say tbl_books?

like image 469
Ravi Avatar asked Jun 30 '10 11:06

Ravi


People also ask

How do you check if a table is used in any stored procedure?

Using SQL query, we can find out the list of the tables used in the stored procedure, using types of joins like inner join, outer join etc. Using SYSOBJECTS and SYSDEPENDS, we can get all the tables, stored procedure and other database object-related information.


2 Answers

Use something like this:

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%'
like image 92
George Dontas Avatar answered Oct 01 '22 23:10

George Dontas


Initially I'd try sp_depends.

Syntax: sp_depends objname[, column_name]

For objname you can supply any object name, for example a table, view or sproc.

like image 41
AdamH Avatar answered Oct 01 '22 23:10

AdamH