Is it really bad practice to “go backward” with a foreign key?

I was wondering if there is bad practice to have file_table { id, name, status}and extra_data table { id, fileId FK(file.id), otherData}. So far, all my tables go forward, and I never needed to get the identifier of one table, and then make a request to get more data using the identifier.

Is this a bad practice, and if so, why?

+3
source share
4 answers

This is not a bad practice. In fact, it looks like a reliable design. Right now you have established a “relationship” with table files and extra_data. However, in order to normalize the database, you must take into account the power of the connection between the tables. Depending on this power, you will know how to place the FK, or maybe you have created a new relationship table. More about power can be found here.

+4
source

It's fine. Your table, designed as laid out, states that one file_table entry can be associated with 0 or more extra_data entries. However, one extra_data entry can only be associated with one file_table entry.

What do you mean, going back?

+5
source

.

+3

, - . ?

0

Source: https://habr.com/ru/post/1722029/


All Articles