MySQL foreign key constraint

I have a complex object that I am trying to store in a database.

I feel that for every case where I would like to limit the possible values, I have to store the values ​​in a table and have a foreign key constraint. I have a feeling that it will be more flexible than ENUM.

The problem is that there are many cases where I would like to limit the values. (the data also branches, and there are times when I would join the table in different places)

Therefore, I will have to join every time I get a currency value, unit of measure, etc. - exponentially increasing the number of associations.

What are your suggestions on this?

Edit:

There are probably 15-20 different types of associations that I could use, some 3 levels deep

+3
source share
1 answer

I see three possible methods for implementing constraints:

One could attach a random record of any categorical variable in a separate table and have a foreign key pointing to this table whenever referenced. This can help keep the database cleaner and easier to maintain in many cases. Knowing that the "Status" attribute of your users is a numerical variable from 1 to 50, and not a string, which can be "MA", "ma", "Mass" or "Massachusetts", will certainly support your database administrators ( and developers and thus end users) are happy.

, , , , CHECK (MySQL ). , , .

, , -. , ( ..) , SQL.

, . , , (500 . ) (20 ) . , , , , .

, ENUM, , , , . , . SELECTS INSERT/UPDATE, , .

+1

All Articles