How to run Trigger sqlserver

Asked

Viewed 1,456 times

0

How can I execute a Trigger in unit tests. I have a Trigger I have a Rigger as an example:

    ***-- Create one trigger with two inserts:***
create trigger trg_I_Table_1 
ON Table_1 
FOR INSERT
as
insert into Table_2 (Col_1, Col_2, Col_3) select Col_1, Col_2, Col_3 
from inserted
insert into Table_3 (Col_1, Col_2, Col_3) select Col_1, Col_2, Col_3 
from inserted
go

1 answer

2


Trigger runs automatically before or after the execution of the Insert, delete or update commands. I know no other way to execute a Rigger without executing those commands.

CREATE OR REPLACE TRIGGER department insert update   
BEFORE INSÈRT OR UPDATE ON department   
FOR EACH ROW   
DECLARE   dup flag INTEGER;   
BEGIN    
NEW.dept name := UPPER(:NEW.dept name);  
END;

You need to tell which commands will fire Trigger, in this example we have the commands of Insert and update. The moment that will be triggered, in case it would be BEFORE INSERT or UPDATE Department and finally the necessary updates.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.