Quantcast
Channel: CodeFari
Viewing all articles
Browse latest Browse all 265

Find all stored procedures related to table in database in SQL Server

$
0
0
There are many different ways to find all stored procedures related to specific table, some are described below.

Using sp_depends: This is the system stored procedure which can use to find all users defined stored procedures related to specific table.


USE[DB_NAME]
GO

EXECsp_depends@objname=N'TBL_NAME';
GO


Note: sp_depends does not always return accurate results.

See following script this will help you to find stored procedures related to specific table.


----Script 1
SELECTDISTINCTso.name
FROMsyscommentssc
INNERJOINsysobjectssoONsc.id=so.id
WHEREsc.TEXTLIKE'%tablename%'

----Script 2
SELECTDISTINCTo.name,o.xtype
FROMsyscommentsc
INNERJOINsysobjectsoONc.id=o.id
WHEREc.TEXTLIKE'%tablename%' 



Referral sites: http://blog.sqlauthority.com/2006/12/10/sql-server-find-stored-procedure-related-to-table-in-database-search-in-all-stored-procedure/ 

Viewing all articles
Browse latest Browse all 265

Trending Articles