Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all stored procedures where table is being used in SQL Server

Tags:

sql-server

I need the query or code in SQL Server to get all the stored procedures in which table is being used in the server (need all stored procedures in all databases on that server).

SELECT * 
FROM sys.procedures 
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%[dbo].[Batch]%.

Above query will give in the current database but I need the query to get from all the databases in that server.

Thanks. Sandeep

like image 410
Sandeep Avatar asked Oct 19 '25 14:10

Sandeep


1 Answers

Try this:

select * from sysobjects where id in 
(select id from syscomments where text like '%myquery%')
order by [name]

where "myquery" is the name of the table. You need to run this on each database on the server individually.

like image 196
Melanie Avatar answered Oct 22 '25 04:10

Melanie