Trigger if updating inserting
Results VALUES (' COLUMNS_UPDATED says I updated col3'); ELSE IF COLUMNS_UPDATED() & 3 = 3 INSERT INTO dbo.Results VALUES (' COLUMNS_UPDATED says I updated col1 AND col2'); ELSE IF COLUMNS_UPDATED() & 2 = 2 INSERT INTO dbo.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.Results will be where the actions of the trigger are tracked. Results VALUES (' UPDATED says I updated col1'); IF UPDATE(col2) INSERT INTO dbo.The There Is ATrigger On This Table will be the table with the trigger that is fired to test each scenario. Results VALUES (' UPDATED says I updated col2'); IF UPDATE(col3) INSERT INTO dbo.It is a well-known fact that triggers can be detrimental to performance of a SQL Server database and should be used sparingly.
TRG_BEFORE_EMP_UPDATE' --Creating person_records table. CREATE TABLE person_records ( PERSON_ID number(10) primary key, FIRST_NAME varchar2(50), LAST_NAME varchar2(50), HIRE_DATE date, UPDATED_BY varchar2(20), UPDATED_DATE date ); CREATE OR REPLACE TRIGGER trg_before_person_update BEFORE UPDATE on person_records FOR EACH ROW DECLARE username varchar2(20); BEGIN SELECT USER INTO username FROM dual; -- Setting updated_by and updated_Date values. Triggers can be set to run as a part of any combination of INSERT, UPDATE, and DELETE statements.Often the actions undertaken by the trigger only need to happen in certain scenarios where specific columns have been affected.Triggers in different schemas can have the same name.It is possible to define multiple triggers for a given table that have the same trigger event and action time.