I am designing Db where It has 2 tables
- Line Item table
- Price Table
Each line item can be of type Lot or Unit Lot is kind of group of Line item having same price. So there is Many Line items to one price relation and there is Unit Line item where each of will have a different price (so there is one - one to relation)
So now, I have 2 tables with 2 kind of relation ship between them price(unit) 1 to 1 Line Item Price(lot) 1 to many Line Item
We have developed a design like below
LineItemTable(Id,PriceIdfk...)
and
Price(Id,Type,CostPrice)
here type indicate if is Unit or Lot
But it does not fully restrict relationship described above
eg: LineItem Table has 3 rows below
(1, LotA, 31)
(2, LotA, 31)
(3, Unit, 32)
and Price table will have below 2 records
(31,Lot,100$)
(32,Unit, 13$)
Imagine changing PriceIdFk on Line Item from 31 to 32, so 2 items belonging to same lot will have different prices which should not happen.
I have tried of creating separate master table as LineItemType(Id,Type)
where it will have only 2 records (1,Unit) and (2,Lot)
and have this Id referred in PriceTable having one more column LineItemTypeFk, but this does not make much difference as 2 items belonging to same lot can have different price.
I guess I am identifying the entities in wrong way but I could not find any solution where this case fits.
If an item is member of the group, then the group price applies; otherwise the item price applies.
Notes
Option 2
As per comments below, to keep
GRPinitem.If an item is member of the group G00, then the item price applies, otherwise the group price applies.