I have a trigger that fires when insert / update FOR UPDATE, INSERT
I check if the field has changed with:
if update (nome)
--faça algo
How do I know if I am inserting a record in the table to be able to record a log?
I have a trigger that fires when insert / update FOR UPDATE, INSERT
I check if the field has changed with:
if update (nome)
--faça algo
How do I know if I am inserting a record in the table to be able to record a log?
Jeterson, I have more knowledge in Oracle, but researching a bit with key terms, I think it will solve your problem.
SQL_STATEMENT
These are the conditions and actions of the trigger. Trigger conditions specify additional criteria that determine whether DML, DDL, or logon events cause the trigger actions to be executed.
A trigger is created to check or change data based on a definition or modification of data. He should not return to the user.
DML triggers use the logical (conceptual) tables
deleted
andinserted
.
As Documentation - CREATE TRIGGER (Transact-SQL)
The
deleted
table stores copies of affected rows during instructionsDELETE
andUPDATE
. While executing aDELETE
or% with%, the rows are excluded from the table of triggers and transferred to theUPDATE
table. Thedeleted
table and the triggers generally do not have lines in common.
As per Documentation - Use inserted and excluded tables (Transact-SQL)
According to the documentation, to know if you are inserting a record, you can do the following:
IF EXISTS (SELECT 1 FROM deleted)
-- update