5
I need to create a Trigger that is triggered every time there is an insertion event in the table, before the insertion is made, it checks a condition, if the condition is met it changes the value of a certain field being inserted.
Example:
-- id do registro atual que esta sendo inserido
if id_pai = 0 or null
-- ela pega este ID, faz um select em outra tabela ( select id from tabela2 where id_nota = id_nota.
-- pega o resultado que seria o ID do registro da tabela2 e insere no campo
-- id_pai do registro que esta sendo inserido.
end;
I’ve been researching some models like how to build Rigger, but I don’t know how to work on the issue of her manipulating the field being inserted, and changing the value.
You must use a Rigger
INSTEAD OF
, and in it you manipulate the data by selecting the data sent to the tablesinserted
anddeleted
, and in an update the tableinserted
will have the new data and tabledeleted
will have the old data records.– Marciano.Andrade
I put the answer below to your question, working 100% but I would recommend doing this via stored Procedure and run by an external software, because Trigger consumes a lot of resources.
– Dorathoto
Your answer will burst if more than one line is added to the same index, I posted mine.
– Marciano.Andrade