Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best database design for product with different price for each attributes

What's the best database design for the following problem:

I have a product with several attributes like color, size, material. Depending on these attributes I want to calculate the total price of a product. Every attribute can hold a specific price. So the price of the product is the sum of all its attribute's costs.

like image 606
killebytes Avatar asked May 15 '11 11:05

killebytes


People also ask

What is attribute database design?

In general, an attribute is a characteristic. In a database management system (DBMS), an attribute refers to a database component, such as a table. It also may refer to a database field. Attributes describe the instances in the column of a database.


1 Answers

First idea would be 3 tables

  • Product (name, description et)
  • Attribute (colour, size, material etc)
  • Many-many link ProductAttribute (productkey, attributekey, price)

A SUM on ProductAttribute per Product would give the price

If you have a fixed and finite set of attributes, then these could be separate columns in a single product table with a computed column to add them up. However, my feeling is that you have a variable number of attributes for each product. So factor then out into a separate table.

Try not to stray into EAV territory of course... :-)

Edit: after question update

I'd use Object Role Modelling to capture the model before I think about implementing.

The fact or size per colour changes the design considerably

like image 198
gbn Avatar answered Oct 20 '22 10:10

gbn