5

I want to check all SPs/function that reference a particular table in mysql. I found a query which I belive is to check the same in sql server:

SELECT Name
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%tablename%'

But in mysql it says 'Table sys.procedures doesn't exist'

Sahil Sharma
  • 3,847
  • 6
  • 48
  • 98

2 Answers2

10
select * from information_schema.ROUTINES where ROUTINE_DEFINITION like '%tableName%'; 
Nickhil
  • 1,267
  • 10
  • 11
4

You need to query Mysql.proc table, here's the documentation:

The mysql.proc table contains information about stored procedures and stored functions. It contains similar information to that stored in the INFORMATION SCHEMA.ROUTINES table.

Your query would be:

SELECT *
FROM Mysql.proc
WHERE type = 'PROCEDURE'
AND body LIKE '%tablename%';
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102