Joseph Caruana
Joseph Caruana

Reputation: 2271

Normalization and Relationships

I have master entity MasterA that has a detail entity DetailB. I have a separate entity DetailC that has a foreign key to DetailB.

In my queries I query a lot the DetailC list but I must query DetailC in relation to MasterA. In this case does it make sense to make a foreign key relationship between DetailC and MasterA to speed up querying. (rather than doing a join with DetailB). At the application layer, I would make sure that the FK in DetailC is in sync (with what is specified at DetailB). Thanks!

Upvotes: 0

Views: 93

Answers (2)

No'am Newman
No'am Newman

Reputation: 6477

You could add a field to DetailC which would be a foreign key with respect to MasterA. But if DetailC has a relation with DetailB and DetailB has a relation with MasterA, then this extra field would be redundant. Strict normalisation would say that there should not be such a field, but you should be able to relax the normalisation rules as long as you can guarantee that there will be no discrepancies in the data.

Upvotes: 1

TaeV
TaeV

Reputation: 738

I think it depending on what about your data.

If in your opinion you think DetailC and MasterA have something related, i think make sense to do that.

Or if you worry about efficiency, i think in design trade-off is always happen. In this case you have to increase your data size to trade with your speed (or your convenient).

Upvotes: 1

Related Questions