Triggers Flashcards

1
Q

What is a trigger

A

Like a stored procedure can be invoked repeatedly.
Can enable and disable but can’t explicitly invoke it.
The DB automatically invokes it.

Fires when the ‘triggered’ event occurs.

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

Compound Trigger

A

Can act before and after an UPDATE, INSERT or DELETE has occurred. Allows a trigger to process similar to a stored procedure without having to write such a procedure to call from a traditional trigger.

Can be used to avoid the mutating table error or to process and accept or reject updates to a table based upon desired criteria

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

How are triggers classified

D D C I

A

DDL TRiggers

DML TRiggers

Compound Triggers

INSTEAD Of Triggers

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

Trigger Execution Hierarchy

how is it followed when a trigger is fired

B N T F

A

BEFORE - statement level fires first

Next, BEFORE - row-level fires once for each affected row

Then, AFTER - row-level fires once for each affected row. This event alters between BEFORE and AFTER row level Triggers.

Finally, the AFTER statement-level trigger fires

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

DDL Trigger

A

Associated with Data Definition Language (DDL)

Such as:
Dropping a Table
Altering a Column
Execute every time a DDL statement is executed

GENERALLY CREATED BY DBA for auditing and enforcement

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

DML Trigger

And when is a DML Trigger fired

A

Data Manipulation Language
Fires at
row level each row is updated, insert or deleted
FOR EACH ROW Option

statement level - triggered for each SQL statement executed

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

Compound Trigger and fires when…

A

Allows different blocks within a trigger to be executed at different timing points.
Declaration section and section for each timing point. Accessed from SQL statement

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

Compound Trigger timing points

A

BEFORE The firing statement
BEFORE Each row that the firing statement affects
AFTER Each row that the firing statement affects
AFTER The firing statement

statement and row level can be put up in a single trigger

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

INSTEAD of Trigger and when it fires

A

In the CREATE trigger is an alternative to BEFORE and AFTER options.

Transparent way to modify views that can’t be modified through Update, Insert and Delete statements

Fires the trigger instead of executing the trigger statement. Performs the operation on the underlying tables

Default activated for each row
View can’t be update, delete or insert if contains
Set operations, group functions, group by, connect by, start with or distinct or joins a subset of join views

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