Find the Table Dependencies of a Stored Procedure in MySQL

Tags: MySQL, SQL

Microsoft SQL Server has the handy dandy View Dependencies functionality.  How can you view dependencies in MySQL?   Well I needed to get the dependent tables for the stored procedures in a schema.  Here's a query to do that:

 
SELECT 
TABLE_SCHEMA
,TABLE_NAME
,ROUTINE_NAME
,ROUTINE_SCHEMA
FROM information_schema.tables
INNER JOIN information_schema.routines
ON routines.routine_definition
LIKE Concat('%', tables.table_schema, '.', tables.table_name, '%')
WHERE ROUTINE_SCHEMA ='MY SCHEMA'

No Comments

Add a Comment