100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Database Triggers & Using Triggers $15.49   Add to cart

Thesis

Database Triggers & Using Triggers

 2 views  0 purchase
  • Course
  • Institution

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

Preview 2 out of 11  pages

  • March 12, 2022
  • 11
  • 2021/2022
  • Thesis
  • Asim
  • Unknown
avatar-seller
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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller asimahsan45. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $15.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

76799 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$15.49
  • (0)
  Add to cart