HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Efficient database design for multiple price based on quantity and attribute

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
pricedesignefficientquantitydatabaseformultiplebasedandattribute

Problem

I have a data sample for products with different prices depending on quantity and attributes. The price might be updated occasionally (not too frequently).

PID | Name                | Type  | Colour  | Colour Print | Quantity: 1 to 149 |   150 to 199| 200 to 249 |250 to 499
1   |White ABC Product    |ABC    |White    |1CP           |2.34|2.07   |1.82|1.51
2   |White ABC Product    |ABC    |White    |2CP           |2.6 |2.31   |1.97|1.62
3   |White ABC Product    |ABC    |White    |3CP          |2.86|2.55|2.14|1.77
7   |Red ABC Product      |ABC    |Red      |1CP           |2.39|2.12|1.87|1.56
8   |Red ABC Product      |ABC    |Red      |2CP           |2.65|2.36|2.02|1.67
9   |Red ABC Product      |ABC    |Red      |3CP           |2.91|2.6|2.19|1.82
12  |White XYZ Product    |XYZ    |White    |1CP           |2.69|2.38|2.09|1.74
13  |White XYZ Product    |XYZ    |White    |2CP           |2.69|2.38|2.09|1.74
14  |White XYZ Product    |XYZ    |White    |3CP           |3.29|2.93|2.46|2.04
18  |Emerald  XYZ Product |XYZ    |Emerald  |1CP           |2.74|2.43|2.14  |1.79   
19  |Emerald  XYZ Product |XYZ    |Emerald  |2CP           |3.04|2.71|2.32  |1.91   
20  |Emerald  XYZ Product |XYZ    |Emerald  |3CP           |3.34|2.98|2.51  |2.09


So basically, I can design the database as the same structure as the above data sample and dump all data into the table (a lot of repetition) or I can do something like this:

Product Table:
---------
--Product id
--Product name {ABC, XYZ, PQR...so on}

Colour Table:
-------
--Colour id
--Colour value {white, red, emerald, and so on}

Colour Print Table 
--------
--Colour print id
--Colour print value {1CP, 2CP, 3CP}

Quantity Table
--------
--Quantity id
--Quantity value {1-149, 150-199, 200-249,250-499}

Price Table
-------
--Price id
--Product id
--Colour id
--Colour Print id
--Quantity id
--Price


So the price table will look something like this:

```
Price table
price id | product id |colour id | q

Solution

First of all you must define your entities and these form your tables. From what you provide above I can see two tables based on two entities: Product and price.

Then you will add your attributes to each entity such as colour and colour print.

Then you should decide on the nature of your relationships - product has a 1:M relationship with price.

To avoid anomalies in your database you will have to normalise your tables - see https://beginnersbook.com/2015/05/normalization-in-dbms/

Hope this helps :-)

Context

StackExchange Database Administrators Q#195375, answer score: 2

Revisions (0)

No revisions yet.