mysql – How to deal with different obligations/cardinalities in SQL relationships?


I had a big question about how to describe different obligations in relationships with SQL, to better understand how to create the image using MySQL Workbench (before you ask, yes, I tried to use a tool that transforms the diagrams into SQL code but it didn’t seem to work. know how to indicate these peculiar obligations, with the exception of the three that I marked in green in the image) to represent the obligations that are simplest to be described via SQL and those that I still don’t know how to.
In the relationship between table3 and table4 there is nothing that indicates that the table that received the foreign key is optional for the table that appeared, at least I didn’t find it.
In the relationship between table 7 and 8 the same thing, there are two ‘minimum 0’s’, but only the one from table 8 to 7 is easy to describe (just leave the foreign key as nullable), not otherwise.
In representative relationships on the right, things get even stranger:
The relationship between tables 11 and 12 suffers from the same problem that I mentioned in the previous ones; the relationship between 13 and 14 does not make sense, since table 13 cannot receive null data in the foreign key as it is also a primary key; The last relationship (tables 15 and 16) suffers from both problems at the same time.

different obligations in relationships

I would like someone more advanced than me in SQL (regardless of the DBMS used) to answer these questions for me, what should be done in these cases? Change business rules? Merge the tables? Do nothing?

In fact, I still have this doubt regarding relationships in the other two cardinality (1:n and n:m), but I prefer not to ask here either so as not to overload the question, especially since the answers to this cardinality will probably answer about the others as well.



Source link

Leave a Comment