Trigger if updating inserting
Results VALUES (' COLUMNS_UPDATED says I updated col2'); ELSE IF COLUMNS_UPDATED() & 1 = 1 INSERT INTO dbo.Results VALUES (' COLUMNS_UPDATED says I updated col1'); END; -- clear out table TRUNCATE TABLE dbo.This post will explain how to make such a determination by creating a table with a trigger and running through a series of scenarios.This post assumes a basic understanding of what a trigger is and knowledge of the inserted and updated virtual tables. UPDATE bank_transactions SET txn_number = 'NEWTXN8080' WHERE txn_id = 1; UPDATE bank_transactions SET txn_number = 'NEWTXN9595' WHERE txn_id = 2; -- output 1 rows updated. Dhaval Dadhaniya is a software engineer by profession and reader/writter by passion. CREATED_DATE); END; --Inserting values INSERT INTO BANK_TRANSACTIONS values ('1','TXN1234','Peter Thomas','12-MAY-2017','HR',sysdate); INSERT INTO BANK_TRANSACTIONS values ('2','TXN9999','Jemes Patel','10-JUN-2016','HR',sysdate); select * from BANK_TRANSACTIONS; --updating values.
One way to be efficient is to skip sections of the trigger code if that code only needs to run when certain columns have been affected.