Link to home
Start Free TrialLog in
Avatar of shyamaladevib
shyamaladevibFlag for United States of America

asked on

Query to find if a stored procedure is being used anywhere else and also to find table in a server

Hi Experts,
I would need help with a query that can find if a stored procedure is being used in another stored procedure  or any DTS packages for a given server.
And aslo would need help with query to find a table in a given server not just find in a database.
Thanks!
Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image

Use this query to find whether a Stored Procedure is used inside some other Stored procedure.

Replace the search string with your actual Stored Procedure name

Raj
SELECT ROUTINE_NAME, ROUTINE_DEFINITION 
FROM INFORMATION_SCHEMA.ROUTINES 
WHERE ROUTINE_TYPE='PROCEDURE' and
ROUTINE_DEFINITION LIKE '%YourStoredProcedure%'

Open in new window

Avatar of mmr159
mmr159

This is one approach to find table 'table_name' in an entire server:

You can, of course, remove the else statement if you don't want to be bothered with all the places it doesn't exist.
sp_msforeachdb '
use ? 
if exists(
	select * from information_schema.tables
	where table_name = ''table_name''
	)
	print ''Table table_name exists in ?''
else
	print ''Table table_name does not exist in ?''
'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shyamaladevib

ASKER

Thanks!