Triggers Class 12 Informatics Practices Revision Notes
Class 12 Informatics Practices students should refer to the following concepts and notes for Triggers in standard 12. These exam notes for Grade 12 Informatics Practices will be very useful for upcoming class tests and examinations and help you to score good marks
Triggers Notes Class 12 Informatics Practices
,sans-serif;">syntax :
ALTER TRIGGER trigger_name DISABLE;
For example:
ALTER TRIGGER orders_before_insert DISABLE;
Drop a Trigger
syntax :
DROP TRIGGER trigger_name;
For example:
DROP TRIGGER orders_before_insert;
Example:
create or replace trigger check_budget_EMP
after insert or update of SAL, DEPTNO on EMP
declare
cursor DEPT_CUR is select DEPTNO, BUDGET from DEPT;
DNO DEPT.DEPTNO%TYPE;
ALLSAL DEPT.BUDGET%TYPE;
DEPT_SAL number;
begin
open DEPT_CUR;
loop
fetch DEPT_CUR into DNO, ALLSAL;
exit when DEPT_CUR%NOTFOUND;
select sum(SAL) into DEPT_SAL from EMP where DEPTNO = DNO;
if DEPT_SAL > ALLSAL then
raise_application_error(-20325, 'Total of salaries in the department '|| to_char(DNO) || ' exceeds
budget');
end if;
end loop;
close DEPT_CUR;
end; /
More about triggers :
Triggers are not exclusively used for integrity maintenance. They can also be used for
• Monitoring purposes, such as the monitoring of user accesses and modifications on certain sensitive
tables.
• Logging actions, e.g., on tables: Contd..
create trigger LOG EMP
after insert or update or delete on EMP
begin
if inserting then
insert into EMP LOG values(user, ’INSERT’, sysdate); end if ;
if updating then
insert into EMP LOG values(user, ’UPDATE’, sysdate); end if ;
if deleting then
insert into EMP LOG values(user, ’DELETE’, sysdate); end if ;
end;
By using a row trigger, even the attribute values of the modified tuples can be stored in the table EMP LOG.
• automatic propagation of modifications. For example, if a manager is transferred to another department, a trigger can be defined that automatically transfers the manager’s employees to the new department.
More about Triggers
If a trigger is specified within the SQL*Plus shell, the definition must end with a point “.” in the last line. Issuing the command run causes SQL*Plus to compile this trigger definition.
A trigger definition can be loaded from a file using the command @. Note that the last line in the file must consist of a slash “/”.
A trigger definition cannot be changed, it can only be re-created using the or replace clause.
The command drop
After a trigger definition has been successfully compiled, the trigger automatically is enabled.
The command alter trigger
triggers defined on a table can be (de)activated using the command
alter table
The data dictionary stores information about triggers in the table USER TRIGGERS. The information includes the trigger name, type, table, and the code for the PL/SQL block.
Difference b/w For and Do Loops: When No. of repetitions are known then For loop is used, and if the No. of iterations are unknown then do loops are used.
Please click the link below to download pdf file for CBSE Class 12 Informatics Practices Triggers Study Notes