Advertisement
xickoh

Trigger Escaparate

Jun 16th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. CREATE TRIGGER checkQuantidadeEscaparate
  2. ON VendasArtigos
  3. FOR INSERT
  4. AS
  5. BEGIN
  6.  
  7. declare @quantidadeEscaparate int;
  8. declare @quantidadeVendas int;
  9. declare @idArtigo int;
  10. SELECT @QuantidadeVendas=i.quantidade, @idArtigo=i.idArtigo from inserted i;
  11. SELECT @quantidadeEscaparate=quantidade FROM Escaparate e WHERE e.idArtigo = @idArtigo)
  12.  
  13.  
  14. IF @quantidadeEscaparate < @quantidadeVendas
  15. BEGIN
  16. Print 'Quantidade não existente em stock';
  17. ROLLBACK TRANSACTION
  18. END
  19. ELSE
  20. BEGIN
  21. UPDATE Escaparate SET quantidade = quantidade - @QuantidadeVendas WHERE idArtigo = @idArt;
  22. END
  23.  
  24. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement