Advertisement
xickoh

impedir tornar conversas de grupo, individuais

Jul 10th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. CREATE TRIGGER preventChangeConversasType
  2. ON Conversas
  3. FOR DELETE
  4. AS
  5. BEGIN
  6.  
  7. declare @idConversa int;
  8. declare @numPessoas int;
  9. SELECT @idConversa=idConversa FROM deleted;
  10. SELECT @numPessoas=count(*) FROM conversas WHERE idConversa = @idConversa
  11.  
  12. IF @numPessoas < 3
  13. BEGIN
  14. IF EXISTS (SELECT * FROM mensagens WHERE idConversa = @idConversa)
  15. BEGIN
  16. Print 'Esta conversa não se pode tornar uma conversa de grupo, pois já existem mensagens neste grupo';
  17. ROLLBACK TRANSACTION
  18. END
  19. END
  20.  
  21. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement