Lecture 11 Flashcards

1
Q

What is a trigger? How does it work?

A

A stored PL/SQL subprogram associated with a table, it is automatically invoked by the DBMS in response to database changes.
Triggers follow the Event-Condition-Action model:
Event: caused by statments, such as INSERT, UPDATE, or DELETE. Trigger will be fired -BEFORE or AFTER the triggering statement is executed, depending on setup.
A triggering condition is optional, but determines whether the action should go ahead, finally, the action step is a block of PL/SQL statements to be executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do we define a trigger?

A

CREATE [OR REPLACE] TRIGGER name {BEFORE | AFTER | INSTEAD OF} {DELETE | INSERT |UPDATE} etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the two main types of triggers?

A

Row-level triggers, these execute once for each row affected by the triggering event, and statement level triggers, which only execute once no matter how many rows were affected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are OLD. and NEW. in relation to triggers?

A

OLD. is the value of the attribute before a change from UPDATE or DELETE, will be NULL for INSERTS.
NEW. the value of the attribute after an UPDATE or INSERT, NULL for DELETE statements. NEW AS newname or OLD AS oldname to create aliases.
Must be preceded by : in trigger body, but not in when clause.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can we tell what activity caused the trigger to execute?

A

Trigger attributes, the trigger has the INSERTING, UPDATING and DELETING attributes, one will be set to true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Oracle’s execution model?

A

All before statement triggers that apply to the SQL statement -> loop for each row(BEFORE row triggers-> change row -> AFTER row triggers) -> complete integrity constraint checks -> AFTER statement triggers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a mutating table? When can a mutating error occur?

A

A mutating table is one that is currently being modified by an UPDATE, DELETE, or INSERT, or a table that might need to be updated by a DELETE CASCADE referential integrity constraint.
Mutating errors occur when the SQL statements of a trigger read from or modify a mutating table of the triggering statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a constraining table? What are the restrictions?

A

A table a triggering statement might need to read, directly or indirectly(referential integrity constraint).
The statements of a trigger cannot change the PRIMARY, FOREIGN, or UNIQUE KEY columns of a constraining table of the triggering.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly