Advertisement
xickoh

Untitled

Jun 14th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. CREATE TRIGGER verificarEmail
  2. ON cliente
  3. INSTEAD OF INSERT
  4. AS
  5. BEGIN
  6. declare @email CHAR(50);
  7. declare @codPostal CHAR(10)
  8. SELECT @email=i.email, @codPostal=i.codPostal FROM inserted i;
  9.  
  10.  
  11.  
  12. IF NOT EXISTS (SELECT * FROM morada where codPostal = @codPostal)
  13. BEGIN
  14. INSERT INTO morada (codPostal, rua, cidade) VALUES (@codPostal, 'rua', 'morada')
  15. END
  16.  
  17. INSERT INTO clientes (nome, telemovel, nif, codPostal, email, dataNascimento, sexo) VALUES (i.nome, i.telemovel, i.nif, i.codPostal, i.email, i.dataNascimento, i.sexo)
  18.  
  19. IF @email NOT LIKE '%_@__%.__%'
  20. BEGIN
  21. Print 'Email inválido';
  22. ROLLBACK TRANSACTION
  23. END
  24.  
  25.  
  26. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement