I have 3 tables. When you add data to the Production table, the quantity of ingredients that are needed for this product is subtracted from the RawMaterialsWarehouse table.
The Ingredients table shows the ID of the product for which it is consumed.
And the raw materials should be subtracted from the quantity specified in the Ingredients table multiplied by the production quantity
CREATE TABLE RawMaterialsWarehouse (
ID int primary key identity(1,1) not null,
Name varchar(30) not null unique,
amountperunit float not null,
quantity float not null
);
CREATE TABLE Production (
ID int primary key identity(1,1) not null,
ProductsID int foreign key (Products ID) references FinishedProductsWarehouse (ID) not null,
Quantity float not null,
Date date not null
);
CREATE TABLE Ingredients (
ID int primary key identity(1,1) not null,
ProductsID int foreign key (ProductsID) references FinishedProductsWarehouse (ID) not null,
RawMaterialsID int foreign key (RawMaterialsID) references RawMaterialsWarehouse (ID) not null,
RawMaterialQuantity float not null
);
Briefly:
Production: here is the product id and its quantity.
Ingredients: here is the product id for which the raw material is consumed; the raw material id; and the amount of raw material per unit of product.
RawMaterialsWarehouse: here is the total quantity of raw materials.
When Production + : all raw materials specified for this product are deducted from RawMaterialsWarehouse.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…