#Trigger

Pubblicato il: 13 marzo 2021
sul canale di: 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'


In questa pagina del sito puoi guardare il video online #Trigger della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Tech Educators 13 marzo 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 402 volte e gli è piaciuto 23 spettatori. Buona visione!