试图找到一种方法来查找MySQL对象的依赖关系。 E.g函数用于视图,触发器,存储过程和其他功能。对查询或工具有什么建议可以做到吗?
我创建了存储过程来加载每种类型,表,例程和视图的依赖关系。 下面是表格的一个:
CREATE PROCEDURE `sys_get_table_depends` (
p_object_name varchar(256)
)
BEGIN
SELECT
information_schema.routines.routine_type as `object_type`
,information_schema.routines.routine_name as `object_name`
,information_schema.routines.routine_definition as `object_definition`
FROM information_schema.tables
INNER
JOIN information_schema.routines
ON routines.routine_definition LIKE Concat('% ', tables.table_name, ' %') OR
routines.routine_definition LIKE Concat('%.', tables.table_name, ' %') OR
routines.routine_definition LIKE Concat('%`', tables.table_name, '`%')
where tables.table_name = p_object_name
UNION
SELECT
'trigger' as `object_type`
,concat(information_schema.triggers.event_object_table, information_schema.triggers.trigger_name) as `object_name`
,information_schema.triggers.ACTION_STATEMENT as `object_definition`
FROM information_schema.tables
INNER
JOIN information_schema.triggers
ON triggers.ACTION_STATEMENT LIKE Concat('% ', tables.table_name, ' %') OR
triggers.ACTION_STATEMENT LIKE Concat('%.', tables.table_name, ' %') OR
triggers.ACTION_STATEMENT LIKE Concat('%`', tables.table_name, '`%')
where tables.table_name = p_object_name
UNION
SELECT
'view' as `object_type`
,information_schema.views.table_name as `object_name`
,information_schema.views.view_definition as `object_definition`
FROM information_schema.tables
INNER
JOIN information_schema.views
ON views.view_definition LIKE Concat('% ', tables.table_name, ' %') OR
views.view_definition LIKE Concat('%.', tables.table_name, ' %') OR
views.view_definition LIKE Concat('%`', tables.table_name, '`%')
where tables.table_name = p_object_name;
END
但看起来并非所有对象定义都存储在information_schema中。有些是空的定义字段。我的猜测是在MySQL架构中。有什么想法吗?
答案 0 :(得分:1)
尝试这样的事情......
SELECT *
FROM information_schema.tables
INNER
JOIN information_schema.routines
ON routines.routine_definition LIKE Concat('%', tables.table_name, '%');