100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Thesis

Database Triggers & Using Triggers

Rating
-
Sold
-
Pages
11
Grade
A+
Uploaded on
12-03-2022
Written in
2021/2022

This chapter contains • About Triggers • Creating Triggers • Changing Triggers • Disabling and Enabling Triggers • About Trigger Compilation and Dependencies • Dropping Triggers

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Course

Document information

Uploaded on
March 12, 2022
Number of pages
11
Written in
2021/2022
Type
Thesis
Supervisor(s)
Asim
Year
Unknown

Subjects

Content preview

Using Triggers
This chapter contains

 About Triggers
 Creating Triggers
 Changing Triggers
 Disabling and Enabling Triggers
 About Trigger Compilation and Dependencies
 Dropping Triggers

About Triggers

A trigger is a PL/SQL unit that is stored in the database and (if it is in the enabled state) automatically
executes ("fires") in response to a specified event.

A trigger has this structure:

TRIGGER trigger_name

triggering_event

[ trigger_restriction ]

BEGIN

triggered_action;

END;

The trigger_name must be unique for triggers in the schema. A trigger can have the same name as
another kind of object in the schema (for example, a table); however, Oracle recommends using a
naming convention that avoids confusion.

If the trigger is in the enabled state, the triggering_event causes the database to execute the
triggered_action if the trigger_restriction is either TRUE or omitted. The triggering_event is associated
with either a table, a view, a schema, or the database, and it is one of these:

DML statement (described in "About Data Manipulation Language (DML) Statements")

DDL statement (described in "About Data Definition Language (DDL) Statements")

Database operation (SERVERERROR, LOGON, LOGOFF, STARTUP, or SHUTDOWN)

If the trigger is in the disabled state, the triggering_event does not cause the database to execute the
triggered_action, even if the trigger_restriction is TRUE or omitted.

, By default, a trigger is created in the enabled state. You can disable an enabled trigger, and enable a
disabled trigger.

Unlike a subprogram, a trigger cannot be invoked directly. A trigger is invoked only by its triggering
event, which can be caused by any user or application. You might be unaware that a trigger is executing
unless it causes an error that is not handled properly.

A simple trigger can fire at exactly one of these timing points:

Before the triggering event executes (statement-level BEFORE trigger)

After the triggering event executes (statement-level AFTER trigger)

Before each row that the event affects (row-level BEFORE trigger)

After each row that the event affects (row-level AFTER trigger)

A compound trigger can fire at multiple timing points. For information about compound triggers, see
Oracle Database PL/SQL Language Reference.

An INSTEAD OF trigger is defined on a view, and its triggering event is a DML statement. Instead of
executing the DML statement, Oracle Database executes the INSTEAD OF trigger. For more information,
see "Creating an INSTEAD OF Trigger".

A system trigger is defined on a schema or the database. A trigger defined on a schema fires for each
event associated with the owner of the schema (the current user). A trigger defined on a database fires
for each event associated with all users.

One use of triggers is to enforce business rules that apply to all client applications. For example, suppose
that data added to the EMPLOYEES table must have a certain format, and that many client applications
can add data to this table. A trigger on the table can ensure the proper format of all data added to it.
Because the trigger executes whenever any client adds data to the table, no client can circumvent the
rules, and the code that enforces the rules can be stored and maintained only in the trigger, rather than
in every client application. For other uses of triggers, see Oracle Database PL/SQL Language Reference.


Creating Triggers
To create triggers, use either the SQL Developer tool Create Trigger or the DDL statement CREATE
TRIGGER. This section shows how to use both of these ways to create triggers.

By default, a trigger is created in the enabled state. To create a trigger in disabled state, use the CREATE
TRIGGER statement with the DISABLE clause.

About OLD and NEW Pseudorecords
$15.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
asimahsan45

Also available in package deal

Get to know the seller

Seller avatar
asimahsan45 Global University
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
3 year
Number of followers
0
Documents
33
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions