Anda di halaman 1dari 5

Q. What is trigger?

Trigger are similar to Procedure and function Trigger must be store in stand alone object in the database. A Trigger is executed implicitly whenever the triggering event happens. Trigger does not accept argument. racle allows you to define procedures that are implicitly executed when an !"#$%T& 'P(AT$& or ($)$T$ statement is issued against the associated table. These procedures are called database triggers. Q. When we can use the trigger? *aintaining +onstraint integrity constraint not possible. #o we can use trigger to maintain those integrity constraint. Auditing information in other table to chec, who made the changes in current table. Automatically signalling other program that action needs to be ta,e place when change is made to other table. automatically generate derived column values prevent invalid transactions enforce complex security authori-ations enforce referential integrity across nodes in a distributed database enforce complex business rules provide transparent event logging provide sophisticated auditing maintain synchronous table replicates Q. .ow many type of trigger? (*) !nstead of #ystem Trigger Q. What is (*) trigger? (*) trigger fire by (*) statement. (*) trigger can be defined for insert& update and delete operation. $x. +reate or replace trigger 'pdatemajor After insert or delete or update " #tudent (eclare +ursor c/stat !# #elect major&count012 total/students&sum0+urrennt /credit2 Total/credits 3rom students 4roupby major5

6egin (elete from major/stats5 3or v/statrecords !n c/stat loop !nsert into table5 $nd loop5 $nd updatemajorstats5

Q. What is instead of trigger? !nstead of trigger can be defined on views. 'nli,e a (*) trigger which execute in addition to the (*) operation& an !nstead of trigger will execute instead of the (*) statement that fired it. !nstead of trigger must be row level trigger. $x. We can insert row in view if it is join of two table. +reate or %eplace trigger classroom !nstead of insert on class/room view (eclare 7/room/id 6egin #elect room/id !nto v/room/id 3rom rooms Where building 89new.building And room/number 9new9room/number 'pdate classed #et room/id 8v/room/id Where department 89new.department $nd 5 :; Tigger closed with trigger name. Q. What is #ystem trigger? A system trigger fires when a system event such as database start;up or shutdown& occurs rather than on (*) operation on a table. !t can also fire on (() operation #uch as table creation. $x. We want to records whenever data dictionary objects are created.

We will create one log table. +reate table ddl/creation 0 'ser/id varchar<0=>2& bject/type &object/name&object/owner&creationdate 2 +reate or replace trigger )og+reation After create on schema 6egin !nsert into ddl/cration values 0user&sys.dictionary/obj/type&sys.dictionary/obj/name&sys.dictionary/obj/owner&sys date2 $nd5 Q.What is general syntax for trigger? A. +reate or replace tigger trigger/name 6efore? after? instead of ? trigger event @%eferencing clauseA @When trigger/+onditionA @3 % $A+. % WA Trigger/body5 Q. .ow *any type of trigger we can create? (*) can be fired on insert update or delete 0#tatement category2. Trigger can fired before or after statement execute.0Timing category2. +an be fired once per affected row or statement 0)evel category2. Total =1<1<8B< possible type. Q. What is difference between row level and statement level triggerC !f the trigger is row level it will fire once for each row affected by trigger statement. #tatement level trigger it will fire once either before or after the statement. A row level trigger identified by the 3 % $A+. % W clause in the trigger definition. Q. What are the correlations identifiers in %ow )evel trigger? A row level trigger fire once per row processed by the triggering statement. We can access the data in the row that is currently being processed. This we can accomplish through two correlation identifier. 9old and 9new A correlation identifier is a special ,ind of P)C#Q) bind variable.The colon in front of each indicates that they are bind variable $x. coming soon DEF Q. .ow can write condition on trigger? When clause is valid for row level trigger only.

The trigger body will execute only those rows which will meet the condition.

$x. +reate or replace trigger chec,credit 6efore insert or update of currentcedfit on students 3or each row When 09new.current/creditsG <>2 6egin C1trigger body1C $nd 5 Q. What are the triggers predicates? A. !nserting& updating and deleting. $x. +reate or replace trigger logchanges 6efore insert or delete or update on registered/students 3or each row (eclare 7/changeType char0B25 6egin !f inserting then C1 T%'$ if the triggering event is an !nsert false otherwise1C 7/changeType 98 !5 $)#!3 updating the 7/changeType 98 H' $lse 7/changeType 98IdI5 $nd if5 Q. What type of view we can not modified direct? A.if view contain #et operator Aggregate function 4roup 6y (istinct Join Q. #imple example of system trigger? A. create or replace trigger @#chema.Atrigger/name 6efore?After Kddl/event/list?database event/listL n (atabase schema When +lause Trigger/body5 Q. What are the different event we can fired in system trigger? #TA%T'P9 After 9 3ired when an instance is start up #.'T( W"96efore93ired when an instance is shut down.This event may not fire when system shut down abnormally. #$%7$%$%% %9 A3T$%9fired when an error occurs.

) 4 " 9After9 fired when user has successfully connected to the database ) 4 3396efore9fired at the start of user logoff. +%$AT$9 6efore&after 9fire before or after a schema object is created. (% P A)T$%

Q. What are the differences for database vs #chema trigger? A #ystem trigger can be defined at the database level or schema level (atabase level trigger will fire whenever the triggering event occurs for the specified schema. $x. +reate or replace trigger loguserconnect After logon on schema 6egin $nd 5 Q. What are the trigger privileges available? +reate Trigger +reate any trigger Alter any trigger (rop any trigger Administer database trigger Q. What is the concept of mutating table in trigger? Table that is currently being modified by a (*) statement 3or a trigger this is table on which trigger is defined.

Anda mungkin juga menyukai