1
Guys, usually whenever I create a Rigger is to perform insertion blocking or only update values.
But this time I just need the system to alert not stopping the person performing the document download. But even though I’m commenting on Trigger’s rollback the system still hangs the insertion. Could someone please help me.
Look at my code:
ALTER TRIGGER ALERTA_CLIENTE_SEM_FOTO on PAGAMENTOS
FOR UPDATE, INSERT NOT FOR REPLICATION
AS
BEGIN
IF (SELECT COUNT(*) FROM Pagamentos P
INNER JOIN INSERTED I ON P.CodCliente=I.CodCliente
INNER JOIN ClientesImagens C ON P.CodCliente=C.CodCliente ) = 0
BEGIN
RAISERROR('O cadastro do cliente está sem foto! Adicione uma foto!',16,1)
--ROLLBACK TRANSACTION
END
END
What’s a lock? It locks the table, doesn’t execute the commit? You should commit the record even with Raiseerror?
– Eduardo Oliveira
Another thing, you’re testing to see if the Count(*) is coming null?
– Eduardo Oliveira
'Lock the insertion' what I mean is that SQL is blocking to continue the operation because the client’s registration has no photo. I don’t want him to stop, I just want him to return the message and continue. Even in the customer’s registration not having photo the person can discharge the document.
– Giovane Barbosa
I’ll find out what you asked for
– Giovane Barbosa
You didn’t inform your
SGBD
correctly. ItSQL Server
orMySQL
? It seems to me that your rule should not stand in aTRIGGER
Yes in a business rule layer in the application. Anyway, one way to solve your problem is to insert your message in a table of alerts and after performing the insertion consult this table to see if any warning should be shown.– Sorack