Question:I’m new to programming and I’m doing a project for myself to consolidate the material. I tried all the methods, but without success. How to correctly write a trigger that, after entering data in the second table in the MOVING_QUANTITY attribute, automatically subtracted SP_PRODUCT_QUANTITY from the first table from MOVING_QUANTITY in the second. And the new result was already recorded in SP_PRODUCT_QUANTITY. In other words, a replacement for the first. I wanted to implement an idea where, for example, I transfer a certain amount of goods and enter the quantity I need, and he took the quantity of a certain product from the warehouse table. Below I have given the tables, and my own trigger, but it does not work correctly as I wanted.
The result I want to achieve:
Answer:You are referencing the wrong column name in the trigger.
Your join condition is wrong. You are not joining to the column in
Moving_list. It will result in error when the
Moving_listtable contains more than 1 row
If you have better answer, please add a comment about this, thank you!