Triggers Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Oracle Trigger Syntax

A

CREATE TRIGGER

TriggerNameMode Event {OR Event }ON TargetTable

[[REFERENCING ReferenceName]

FOR EACH ROW

[WHEN Predicate]]

PL/SQL Block

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

Oracle Execution Algorithm

A
  1. Before statements
  2. For each tuple affected by the triggering statement:
    - Before row triggers are executed
    - Triggering statement is executed + integrity constraints checked on tuples
    - After row triggers
  3. Integrity constraints on tables are checked
  4. After triggers are checked
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Oracle Trigger Execution Order

A

Same event triggers execution order is non-deterministic

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

Oracle: When Error Occurs

A

Rollback of all operations performed by the trigger

Rollback of the triggering transaction

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

Oracle: Cascade Trigger Execution

A

Limit after which error is thrown: 32 triggers

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

Oracle: Mutating Table Access

A

Cannot be touched with ROW Triggers, but can be with statement triggers.

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

Oracle: Conditional Execution

A

Condition can be specified only for row level triggers

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

DB2 Syntax

A

CREATE TRIGGER TriggerName

{BEFORE, AFTER} {INSERT, DELETE, UPDATE}

ON TargetTable

[REFERENCING ReferenceName]

FOR EACH {ROW, STATEMENT}

WHEN Predicate

Procedural SQL Statements

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

DB2 Limitations

A

Only one event (UPDATE, INSERT, DELETE) is allowed for each trigger.

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

DB2 Execution algorithm

A

Transaction T contains a statement S which generates event E.

  1. T’s execution is suspended and its state is saved into a stack
  2. Old and new values of E are computed
  3. Before triggers on E are executed
  4. New values are applied to the DB (modification due to E is actually performed)
    • constraints are checks to avoid recurive invocation on the same procedure.
  5. After triggers due to E are executed.
    • If any trigger contains an action which triggers other triggers, those are executed in a recurive fashion.
  6. The execution state of T is extracted from the stack and T is resumed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Oracle VS. DB2

Reference to Old_Table and New_table in statement triggers

A

Oracle: NO

DB2: Yes

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

Oracle VS. DB2

When clause in statement triggers

A

Oracle: no

DB2: yes

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

Oracle VS. DB2

Execution order between row and statement triggers with same mode

A

Oracle: Specified

DB2: Arbitrary

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

Oracle VS. DB2

Execution order between triggers with same event, mode, granularity

A

Oracle: Unspecified

DB2: Creation order

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

Oracle VS. DB2

More than one triggering event allowed

A

Oracle: Yes

DB2: No

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

Oracle VS. DB2

Forbidden access to the mutating table

A

Oracle: Yes, for row triggers

DB2: No

17
Q

Oracle’s INSTEAD OF

A

An INSTEAD OF trigger is a trigger that allows you to skip an INSERT, DELETE, or UPDATE statement to a table or a view and execute other statements defined in the trigger instead.

18
Q

Oracle VS. DB2

Availability of the INSTEAD OF sematincs

A

Oracle: Yes

DB2: No

19
Q

Oracle VS. DB2

Database modifications allowed in before triggers

A

Oracle: Yes

DB2: Only for new variables