What and when is the best way to use FK's without geting FK "redundancy".
Let's say that i have three tables Account, Category and Product.
1: Table Account
Definition:
- Id, Primary BigInt
- Name, Varchar
2: Table Category
Definition:
- Id, Primary BigInt
- AccountId, BigInt ForeignKey
- Name, Varchar
3: Table Product
Definition:
- Id, Primary BigInt
- AccountId, BigInt ForeignKey - "the black sheep"
- CategoryId, BigInt ForeignKey
- Name, Varchar... and so on
My question(since im no DBA): Is it bad design/plain stupid to use FK AccountId on table Product, when I know that my FK CategoryId points to a table which holds the same FK?
I'm just thinking in terms of the DRY-principle.
Why im wondering is, let's say that I want to get all of the products for Account x. If I don't have the FK AccountId on Product, I'll always have to join the Category table in order to fetch all products for Account x. Which can be quite a performance hit, I'm guessing.
If you have a opinion, and I mean ANY opinion on this subject. Please literatly KILL this thread by writing your point of view on how you think FK's should be used.
Thanks!
Robin