MS SQL Creating Tables and Adding Values by a Trigger
0
votes
1
answer
713
views
Table_A is an existing table which has 3 columns Id (PK), Name, Stock.
I would like to create a trigger to create a table.
For example, Table_A has an item, Id (PK) = 3, Name = Apple, Stock = 10.
By using triggers I would like to create a new table called Table_B and when I write the following code "INSERT INTO Table_B VALUES(3,5)" a new table will be created and it will have 2 columns ProductId and Quanity. At the same time the value for Stock for Table_A will be decreased by 5. Every time I insert something to Table_B I would like them to get added to Table_B and the stock in Table_A to be decreased by the quantity of that item inserted with the related ProductId. Thanks!
Asked by Nikola
(1 rep)
Apr 29, 2021, 01:05 AM
Last activity: Aug 9, 2025, 02:10 PM
Last activity: Aug 9, 2025, 02:10 PM