title: How do I write a trigger for such conditions? (3 tables)
body: <p>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.</p>
  <p>And the raw materials should be subtracted from the quantity specified in the Ingredients table multiplied by the production quantity</p>
  <pre class="lang-sql prettyprint-override"><code>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
  );
  </code></pre>
  <p>Briefly:</p>
  <p>Production: here is the product id and its quantity.</p>
  <p>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.</p>
  <p>RawMaterialsWarehouse: here is the total quantity of raw materials.</p>
  <p>When Production + : all raw materials specified for this product are deducted from RawMaterialsWarehouse.</p>