89 lines
7.5 KiB
HTML
89 lines
7.5 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="SQL triggers" />
|
||
|
<meta name="abstract" content="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." />
|
||
|
<meta name="description" content="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." />
|
||
|
<meta name="DC.subject" content="trigger, SQL, CREATE TRIGGER statement" />
|
||
|
<meta name="keywords" content="trigger, SQL, CREATE TRIGGER statement" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafydb2triggers.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafybeforesql.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyaftersql.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyinsteadofsql.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyhandlersql.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafytransitiontable.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstsqlcontstmts.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmsthctrigger.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafydebugproc.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="rbafysqltrig" />
|
||
|
<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>SQL triggers</title>
|
||
|
</head>
|
||
|
<body id="rbafysqltrig"><a name="rbafysqltrig"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">SQL triggers</h1>
|
||
|
<div><p><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></p>
|
||
|
<p>The statements specified in the SQL trigger are executed each time an SQL
|
||
|
insert, update, or delete operation is performed. An SQL trigger may call
|
||
|
stored procedures or user-defined functions to perform additional processing
|
||
|
when the trigger is executed. </p>
|
||
|
<p><img src="./delta.gif" alt="Start of change" />Unlike stored procedures, an SQL trigger cannot be directly
|
||
|
called from an application. Instead, an SQL trigger is invoked by the database
|
||
|
management system on the execution of a triggering insert, update, or delete
|
||
|
operation. The definition of the SQL trigger is stored in the database management
|
||
|
system and is invoked by the database management system when the SQL table
|
||
|
or view that the trigger is defined on, is modified.<img src="./deltaend.gif" alt="End of change" /></p>
|
||
|
<p><img src="./delta.gif" alt="Start of change" />An SQL trigger can be created by specifying the CREATE
|
||
|
TRIGGER SQL statement. All objects referred to in the CREATE TRIGGER statement
|
||
|
(such as tables and functions) must exist; otherwise, the trigger will not
|
||
|
be created. The statements in the routine-body of the SQL trigger are transformed
|
||
|
by SQL into a program (*PGM) object. The program is created in the schema
|
||
|
specified by the trigger name qualifier. The specified trigger is registered
|
||
|
in the SYSTRIGGERS, SYSTRIGDEP, SYSTRIGCOL, and SYSTRIGUPD SQL catalogs. <img src="./deltaend.gif" alt="End of change" /></p>
|
||
|
</div>
|
||
|
<div>
|
||
|
<ul class="ullinks">
|
||
|
<li class="ulchildlink"><strong><a href="rbafybeforesql.htm">BEFORE SQL triggers</a></strong><br />
|
||
|
BEFORE triggers may not modify tables, but they can be used to verify input column values and also to modify column values that are inserted or updated in a table.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafyaftersql.htm">AFTER SQL triggers</a></strong><br />
|
||
|
The WHEN condition can be used in an SQL trigger to specify a condition. If the condition evaluates to true, then the SQL statements in the SQL trigger routine body are run. If the condition evaluates to false, the SQL statements in the SQL trigger routine body are not run, and control is returned to the database system. This type of trigger is called an AFTER trigger.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafyinsteadofsql.htm">INSTEAD OF SQL triggers</a></strong><br />
|
||
|
An INSTEAD OF trigger is an SQL trigger that is processed “instead of” an SQL UPDATE, DELETE or INSERT statement. Unlike SQL BEFORE and AFTER triggers, an INSTEAD OF trigger can only be defined on a view, not a table.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafyhandlersql.htm">Handlers in SQL triggers</a></strong><br />
|
||
|
A handler in an SQL trigger gives the SQL trigger the ability to recover from an error or log information about an error that has occurred while processing the SQL statements in the trigger routine body.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafytransitiontable.htm">SQL trigger transition tables</a></strong><br />
|
||
|
An SQL trigger may need to refer to all of the affected rows for an SQL insert, update, or delete operation. This is true, for example, if the trigger needs to apply aggregate functions, such as MIN or MAX, to a specific column of the affected rows. The OLD_TABLE and NEW_TABLE transition tables can be used for this purpose.</li>
|
||
|
</ul>
|
||
|
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafydb2triggers.htm" title="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.">Triggers</a></div>
|
||
|
</div>
|
||
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
||
|
<div><a href="rbafydebugproc.htm" title="By specifying SET OPTION DBGVIEW = *SOURCE in your Create SQL Procedure, Create SQL Function, or Create Trigger statement, you can debug the generated program or module at the SQL statement level.">Debug an SQL routine</a></div>
|
||
|
</div>
|
||
|
<div class="relinfo"><strong>Related information</strong><br />
|
||
|
<div><a href="../db2/rbafzmstsqlcontstmts.htm">SQL control statements</a></div>
|
||
|
<div><a href="../db2/rbafzmsthctrigger.htm">CREATE TRIGGER statement</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|