View Full Version : Help with design


Nova
04-16-2010, 09:34 PM
Hey there, I'm having problems with the design of a database that stores information about beer.

Basically I want to be able to compare the prices of beers at different suppliers but I'm not sure how to go about storing this information to start with.

Each beer has one or many container types (bottle, can etc..)
then each container type is sold as a quantity (4 pack, 6 pack etc..)
then on top of this each combination of beer,its container, and the quantity it can be purchased in, is sold at 1 or many suppliers, at different prices for each beer and its quantity(s) and at different prices, depending on the supplier.

I have attached a picture showing my current tables and with their relationships.

Thanks,
Nova

lagbolt
04-19-2010, 01:16 PM
I'd expect to see a 'Product' table that includes the container details before you link in the supplier. Supplier A might only supply kegs, and Supplier B might supply 6 Packs and 8 Packs of the same beer.
So a product table might look like ...
tProduct
ProductID (PK)
BeerID (FK)
ContainerID (FK)
Then, I'd expect a many-to-many relationship between products and suppliers with the link table as follows ...
tProductSupply
ProductSupplyID (PK)
ProductID (FK)
SupplierID (FK)
EffectiveDate
Price

But this depends too on the reality of your situation. I usually develop tables with some test data and knowledge of the inputs and outputs of the system. Mock it all up and see if you can achieve the result you need and if not keep tweaking. Get this part right before you move on.

KenHigg
04-27-2010, 04:53 PM
This is a little overdesigned for my good but...

In the beer suppliers table you need a many on the beer id and then make the beer id and supplier id a composite primary key