sql - List of table names ordered by their foreign key dependency in MySQL -


given mysql database, how obtain list of table names ordered foreign key dependency can delete each table? understand foreign key's stored in key_column_usage table i'm not sure if there utility method obtain table names in correct order. prefer 100% sql solution.

if foreign keys follow naming convention (as should :), simple like

select table_name, group_concat(distinct constraint_name order constraint_name) fk_list   information_schema.key_column_usage  constraint_name rlike 'fk' group  table_name order  fk_list, table_name; 

or, if foreign keys don't follow naming convention, then

select table_name, group_concat(distinct constraint_name order constraint_name) fk_list   information_schema.key_column_usage  referenced_table_name not null group  table_name order  fk_list, table_name; 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -