afranklin
03-23-2010, 09:30 AM
Hi,
Firstly, I hope this question makes sense and secondly that I don't get a prize for the worst question ever asked! Anyway... I'm using MS SQL and have three tables (simplified to make this er, simpler!):
Category
CatID (primary key)
CatName
SubCategory
SubCatID (primary key)
CatID (foreign key)
SubCatName
Item
ItemID (primary key)
ItemName
Each item belongs to a subcategory and each subcategory belongs to a category.
The question is: should my Item table contain a foreign key to SubCatID and CatID or just to SubCatID?
I think the answer should be just to have a foreign key to SubCatID because I can access the CatID through the SubCategory table but I wonder if there is any instance when you might also have the CatID in the item table (e.g. to make things quicker by needing less joins etc.)?
Thanks!
Firstly, I hope this question makes sense and secondly that I don't get a prize for the worst question ever asked! Anyway... I'm using MS SQL and have three tables (simplified to make this er, simpler!):
Category
CatID (primary key)
CatName
SubCategory
SubCatID (primary key)
CatID (foreign key)
SubCatName
Item
ItemID (primary key)
ItemName
Each item belongs to a subcategory and each subcategory belongs to a category.
The question is: should my Item table contain a foreign key to SubCatID and CatID or just to SubCatID?
I think the answer should be just to have a foreign key to SubCatID because I can access the CatID through the SubCategory table but I wonder if there is any instance when you might also have the CatID in the item table (e.g. to make things quicker by needing less joins etc.)?
Thanks!