Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TRIGGER checkQuantidadeEscaparate
- ON VendasArtigos
- FOR INSERT
- AS
- BEGIN
- declare @quantidadeEscaparate int;
- declare @quantidadeVendas int;
- declare @idArtigo int;
- SELECT @QuantidadeVendas=i.quantidade, @idArtigo=i.idArtigo from inserted i;
- SELECT @quantidadeEscaparate=quantidade FROM Escaparate e WHERE e.idArtigo = @idArtigo)
- IF @quantidadeEscaparate < @quantidadeVendas
- BEGIN
- Print 'Quantidade não existente em stock';
- ROLLBACK TRANSACTION
- END
- ELSE
- BEGIN
- UPDATE Escaparate SET quantidade = quantidade - @QuantidadeVendas WHERE idArtigo = @idArt;
- END
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement