S
S
Shultc2018-06-18 17:49:05
MySQL
Shultc, 2018-06-18 17:49:05

Is it bad to have redundant foreign keys in a database?

I want to create a base part of the structure which will look like this:

table_one ---(many)---< table_two ---(many)---< table_three ---(many)---< table_four

As you can see, records from table_four will always be associated with only one record from table_one. But in order to get this information, I will need to do a lot of JOINs every time.
Can I add a foreign key to the table_four table that links it to the table_one table, or is this considered bad practice?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kn0ckn0ck, 2018-06-18
@kn0ckn0ck

It's always a trade-off: normalization vs convenience/performance. Denormalization is often used in practice, so I don’t consider it a bad decision, provided that after that there will be no mess in the database. How to achieve this is another question.
If many joins do not harm performance (for example, there is little data in tables), then it is easier to use views to reduce development time (using these tables in queries) and prevent integrity violations when updating / inserting / deleting.
Different DBMSs have native mechanisms to support denormalized relationships, such as something like materialized views in Oracle.
In general, normalization is the enemy of performance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question