ibm-information-center/dist/eclipse/plugins/i5OS.ic.sqlp_5.4.0.1/rbafydb2triggers.htm

94 lines
6.3 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="concept" />
<meta name="DC.Title" content="Triggers" />
<meta name="abstract" content="A trigger is a set of actions that are run automatically when a specified change operation is performed on a specified table or view. The change operation can be an SQL INSERT, UPDATE, or DELETE statement, or an insert, update, or delete high-level language statement in an application program. Triggers are useful for tasks such as enforcing business rules, validating input data, and keeping an audit trail." />
<meta name="description" content="A trigger is a set of actions that are run automatically when a specified change operation is performed on a specified table or view. The change operation can be an SQL INSERT, UPDATE, or DELETE statement, or an insert, update, or delete high-level language statement in an application program. Triggers are useful for tasks such as enforcing business rules, validating input data, and keeping an audit trail." />
<meta name="DC.subject" content="trigger" />
<meta name="keywords" content="trigger" />
<meta name="DC.Relation" scheme="URI" content="rbafyroutines.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafysqltrig.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafysystrig.htm" />
<meta name="DC.Relation" scheme="URI" content="../dbp/rbaforzahftra.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rbafydb2triggers" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Triggers</title>
</head>
<body id="rbafydb2triggers"><a name="rbafydb2triggers"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Triggers</h1>
<div><p>A <em>trigger</em> is a set of actions that are run automatically
when a specified change operation is performed on a specified table or view.
The change operation can be an SQL INSERT, UPDATE, or DELETE statement, or
an insert, update, or delete high-level language statement in an application
program. Triggers are useful for tasks such as enforcing business rules, validating
input data, and keeping an audit trail.</p>
<p>Triggers can be defined as SQL or external.</p>
<p>For an external trigger, the CRTPFTRG CL command is used. The program containing
the set of trigger actions can be defined in any supported high level language.
External triggers can be insert, update, delete, or read triggers.</p>
<p>For an SQL trigger, the CREATE TRIGGER statement is used. The trigger program
is defined entirely using SQL. SQL triggers can be insert, update, or delete
triggers.</p>
<p><img src="./delta.gif" alt="Start of change" />Once a trigger is associated with a table or view, the
trigger support calls the trigger program whenever a change operation is initiated
against the table or view, or any logical file or view created over the table
or view. SQL triggers and external triggers can be defined for the same table.
Only SQL triggers can be defined for a view. Up to 200 triggers can be defined
for a single table or view.<img src="./deltaend.gif" alt="End of change" /></p>
<p><img src="./delta.gif" alt="Start of change" />Each change operation for a table can call a trigger before
or after the change operation occurs. Additionally, you can add a <em>read</em> trigger
that is called every time the table is accessed. Thus, a table can be associated
with many types of triggers.<img src="./deltaend.gif" alt="End of change" /></p>
<ul><li>Before delete trigger</li>
<li>Before insert trigger</li>
<li>Before update trigger</li>
<li>After delete trigger</li>
<li>After insert trigger</li>
<li>After update trigger</li>
<li>Read-only trigger (external trigger only)</li>
</ul>
<p><img src="./delta.gif" alt="Start of change" />Each change operation for a view can call an instead of
trigger which will perform some set of actions instead of the
insert, update, or delete. A view can be associated with an:<img src="./deltaend.gif" alt="End of change" /></p>
<img src="./delta.gif" alt="Start of change" /><ul><li>Instead of delete trigger</li>
<li>Instead of insert trigger</li>
<li>Instead of update trigger</li>
</ul><img src="./deltaend.gif" alt="End of change" />
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rbafysqltrig.htm">SQL triggers</a></strong><br />
<span><img src="./delta.gif" alt="Start of change" />The SQL CREATE TRIGGER statement provides
a way for the database management system to actively control, monitor, and
manage a group of tables and views whenever an insert, update, or delete operation
is performed.<img src="./deltaend.gif" alt="End of change" /></span></li>
<li class="ulchildlink"><strong><a href="rbafysystrig.htm">External triggers</a></strong><br />
For an external trigger, the program containing the set of trigger actions can be defined in any supported high level language that creates a *PGM object.</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyroutines.htm" title="Routines are pieces of code or programs that you can call to perform operations.">Routines</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../dbp/rbaforzahftra.htm">Triggering automatic events in your database</a></div>
</div>
</div>
</body>
</html>