on venta after Insert as declare @totalLibro int, @idFactura int set @totalLibro = (Select inserted.Cantidad*Libro.Precio from inserted INNER JOIN Libro on inserted.IdLibro=Libro.IdLibro) set @idFactura =(Select inserted.idFactura from inserted) update Factura set Total =Total+@totalLibro where IdFactura=@idFactura
DELETE
Create trigger actualizarTotalDelete on venta after DELETE as declare @totalDelete int, @idFactura int set @totalDelete = (Select deleted.Cantidad*Libro.Precio from deleted INNER JOIN Libro on deleted.IdLibro=Libro.IdLibro) set @idFactura =(Select idFactura from deleted) update Factura set Total =Total-@totalDelete where IdFactura=@idFactura
UPDATE
Create trigger actualizarTotalUpdate on venta after Update as declare @totalDelete int, @idFacturaDELETE int set @totalDelete = (Select deleted.Cantidad*Libro.Precio from deleted INNER JOIN Libro on deleted.IdLibro=Libro.IdLibro) set @idFacturaDELETE =(Select idFactura from deleted) update Factura set Total =Total-@totalDelete where IdFactura=@idFacturaDELETE
declare @totalInsert int, @idFacturainsert int set @totalInsert = (Select inserted.Cantidad*Libro.Precio from inserted INNER JOIN Libro on inserted.IdLibro=Libro.IdLibro) set @idFacturainsert =(Select idFactura from inserted) update Factura set Total =Total+@totalInsert where IdFactura=@idFacturainsert