How to find relationship and cardinality in Mysql?

Asked

Viewed 3,569 times

2

The image below shows a relationship between two tables created from Mysql Workbench.

What I need to know is how I can find this information inside the database.

I need to know exactly what kind of cardinality (1:1 or 1:n).

I already searched inside the "information_schema" and I can’t find.

Relacionamento entre 2 tabelas e cardinalidade

3 answers

5


Cardinality (in this context) is not information found within the database. It’s a concept that we apply in general modeling, to understand how the relationship between the tables is.

We usually refer in these diagrams to the expected cardinality in the relationship. These diagrams are on a more abstract level.

It is even possible to impose cardinality through the various resources of the database as the stored procedures, constraints and triggers. But this does not give an unambiguous information of what the cardinality is, much less is it mandatory.

  • bigown actually tried to do a reversal of an existing bank on a new Workbench project and he did not identify this cardinality, I thought this was possible. Thanks for your help.

1

Solução - MySQL Workbench

I know it’s 2018, but it’s a question I had too and I found the solution. I would like to share with others.

1

  • Remembering that, as @bigown said, it is not an exact figure. Mysql only estimates a value, you can try to elaborate a more precise solution using the ANALYZE TABLE command http://dev.mysql.com/doc/refman/5.6/en/analyze-table.html

  • 1

    Actually this cardinality is something else. This fails to inform the cardinality of the relationship, which is what the question refers to. It informs only if the data vary much or little. Higher cardinality means that all data are different and lower cardinality means that all data are equal.

  • I had already tried to use the SHOW INDEX but could not determine what I need. @feresjorge how should I use ANALYZE TABLE to find out this information?

  • @bigown what I really need is to know if a table has a relationship with another type a LIST or an ASSOCIATION. I don’t know if there’s another technique to figure this out, I saw it at Workbeach and I thought it was stored in the bank.

  • As my answer does not exist, at least not in Mysql. It may be that there is some tool that analyses the data and tries to find out, but it will depend on the existing data. Anyway, there is no way.

  • You can try to find out if the Workbench does reverse engineering as well as it is possible through an EER diagram to have the table creation querys.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.