I have two tables:
tblProducts
-Id int,
-Producto varchar(10),
-Cantidad int
tblVentas
-Idventa
-Idproducto
-Cantidad int
The tblProductos table is related to tblVentas. What I want to realize is that when the sale of a product is added, the quantity field of the table tblProducts is updated. That is, decrease the amount of products once a sale is made.
I am trying to do it in the following way:
CREATE TRIGGER actualiza_cantidad
on tblventas
AFTER INSERT
AS
BEGIN
UPDATE tblProductos set cantidad=cantidad - inserted.cantidad WHERE
tblventas.id= inserted.id;
END
GO