0

With MySQL Workbench it is possible to create a graphical ER diagram; however, this can become very messy when there are many tables and relations, so it might be good to have something like one or more text trees, like this, where TABLE1 has a foreign key to TABLE2A, TABLE2B and TABLE2C, and TABLE2B has a foreign key to TABLE3A and TABLE3B:

TABLE1 -+- TABLE2A
        +- TABLE2B -+- TABLE3A
        |           +- TABLE3B
        +- TABLE2C

and so on. Is there a tool that can produce that?

Edit

Having thought a bit, I realise that I can create a list like this:

mysql> select distinct table_name,referenced_table_name 
    -> from key_column_usage 
    -> where table_schema='demoplay' 
    -> and referenced_table_name is not null 
    -> order by table_name;

I can probably create a greater_than function based on this in python and then sort things, and perhaps from there print it out nicely.

2
  • How should it handle the linking tables that are used for enforcing many-to-many relationships? Jul 28 '20 at 15:36
  • Not as anything special - I'm not after a perfect representation, only after the order relation imposed by the FK relationships.
    – j4nd3r53n
    Jul 28 '20 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.