#Trigger

Published: 13 March 2021
on channel: Tech Educators
402
23

#Trigger #SQL How to create trigger in SQL | Trigger for insert update and delete in SQL Live Demo
What is a trigger?
A trigger is a statement that is executed automatically by the system as a side effect of a modification to the database.

To design a trigger mechanism, we must: ECA (E-event, C-condition, A-action)
1) Specify the conditions under which the trigger is to be executed.
2) Specify the actions to be taken when the trigger executes.

Trigger: A trigger is a stored procedure in database which automatically invokes whenever a special event in the database occurs. For example, a trigger can be invoked when a row is inserted into a specified table or when certain table columns are being updated.

Example-01 Create a trigger t1 on student table which will not allow any modifications on Friday.

create or replace trigger t1
before insert or update or delete on student
begin
if to_char(sysdate,'dy')='fri' then
raise_application_error(-20001,'Can not Manipulate Today');
end if;
end;

Trigger Created.

insert into student values(11, 'Tushar');
insert into student values(11, 'Tushar')
*
ERROR at line 1:
ORA-20001: Can not Manipulate Today
ORA-06512: at "SYSTEM.T1", line 3
ORA-04088: error during execution of trigger 'SYSTEM.T1'



update student set roll_no=20 where roll_no=1;
update student set roll_no=20 where roll_no=1
*
ERROR at line 1:
ORA-20001: Can not Manipulate Today
ORA-06512: at "SYSTEM.T1", line 3
ORA-04088: error during execution of trigger 'SYSTEM.T1'


delete from student where roll_no=1;
delete from student where roll_no=1
*
ERROR at line 1:
ORA-20001: Can not Manipulate Today
ORA-06512: at "SYSTEM.T1", line 3
ORA-04088: error during execution of trigger 'SYSTEM.T1'


On this page of the site you can watch the video online #Trigger with a duration of hours minute second in good quality, which was uploaded by the user Tech Educators 13 March 2021, share the link with friends and acquaintances, this video has already been watched 402 times on youtube and it was liked by 23 viewers. Enjoy your viewing!