Solved

List all stored procedures that contain a specified table in T-SQL

Posted on 2013-01-15
3
346 Views
Last Modified: 2013-01-15
Hi Experts,
Working with a SQL Server 2008 R2 database that has hundreds of Stored Procedures (sprocs).

An employee built a table called mh_client. mh_client needs to be replaced as it is causing issues.

I would like to run a query that can list all the sprocs that contain mh_client so I can discuss the ramifications of these changes with the rest of the team.

Any advice?

John
0
Comment
Question by:JohnAeris
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 38777465
try this

select dISTINCT so.name
FROM syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
WHERE sc.TEXT LIKE '%mh_client%'
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 500 total points
ID: 38777470
above will return all sp's views and functions

for only stopre procedures try this

select distinct so.name
FROM syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
WHERE sc.TEXT LIKE '%mh_client%'
and xtype='P'
0
 

Author Closing Comment

by:JohnAeris
ID: 38777643
Thank you!
Actually, the table appeared in views as well, which was not anticipated, so your first code was the most useful!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Import New Records From Access Table To SQL Database Table 7 30
Procedure syntax 5 38
IIF in access query 19 21
SQL Syntax Grouping Sum question 7 24
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question