Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Product Manuals » ElevateDB Version 2 SQL Manual » DDL Statements » CREATE TRIGGER |
CREATE TRIGGER <Name> <ActionTime> <Type> ON <TableName> [AT <ExecutionPos>] [WHEN <Condition>] <BodyDefinition> [DESCRIPTION <Description>] <ActionTime>=BEFORE|AFTER|ERROR <Type>=INSERT|UPDATE [OF <UpdateColumns>]|DELETE|LOAD UPDATE|ALL <UpdateColumns>= <ColumnName> [,<ColumnName>] <BodyDefinition> = BEGIN [<Declaration>;] [<Declaration>;] [<Statement>;] [<Statement>;] [EXCEPTION] [<Statement>;] END
Operation | OLDROW/NEWROW Usage |
INSERT | OLDROW values are the column values for the INSERT operation. NEWROW values are the column values after the INSERT operation, and are all NULL for any BEFORE LOAD UPDATE triggers. |
UPDATE | OLDROW values are the primary key values used to find the row for the UPDATE operation. NEWROW values are the column values after the UPDATE operation, and are all NULL for any BEFORE LOAD UPDATE triggers. |
DELETE | OLDROW values are the primary key values used to find the row for the DELETE operation. NEWROW values are the column values after the DELETE operation, and are all NULL for any BEFORE LOAD UPDATE triggers. |
ERROR | OLDROW and NEWROW values depend upon the operation being performed during the loading of the update. Use the OPERATION function to determine how to modify or examine the column values. |
-- This trigger calls the external -- SendMail procedure with which group to -- send the email to along with the new -- value of the Notes column for the customer -- being updated CREATE TRIGGER "NotesUpdate" AFTER UPDATE OF "Notes" ON "Customer" BEGIN CALL SendEmail('CustomerReps',NEWROW.Notes); END -- This trigger logs any insert errors that -- occur during a LOAD UPDATES for -- the Customer table into a table called -- LoadErrors CREATE TRIGGER "LogInsertError" ERROR INSERT ON "customer" WHEN LOADINGUPDATES() BEGIN DECLARE ErrorData VARCHAR DEFAULT ''; SET ErrorData = 'Cust #: ' + CAST(NEWROW.CustNo AS VARCHAR); SET ErrorData = ErrorData + 'Name: ' + NEWROW.Company; SET ErrorData = ErrorData + 'Error #: ' + CAST(ERRORCODE() AS VARCHAR); SET ErrorData = ErrorData + 'Error Msg: ' + ERRORMSG(); EXECUTE IMMEDIATE 'INSERT INTO LoadErrors (''Customer'',''INSERT'', ''' + ErrorData + ''''; END -- This trigger updates any new row with -- a timestamp of when the row was inserted -- into the Customer table. The AT clause -- is used to ensure that this trigger always -- fires first before any other triggers CREATE TRIGGER "SetTimeStamp" BEFORE INSERT ON "customer" AT 1 BEGIN SET NEWROW.CreatedOn = CURRENT_TIMESTAMP(); END -- This trigger examines the primary key -- values for an update being loaded into -- the Customer table. If the SiteID column -- value for the update does not match the -- SiteID column in the System table in the -- same database, then the loading of the update -- is aborted using the ABORT statement. -- NOTE: the column being filtered on, in this case -- the SiteID column, must be part of the primary -- key in order for it to be non-NULL in the -- OLDROW column values for UPDATE and DELETE -- operations. CREATE TRIGGER "FilterUpdates" BEFORE LOAD UPDATE ON "customer" BEGIN DECLARE SiteID INTEGER DEFAULT 0; EXECUTE IMMEDIATE 'SELECT SiteID INTO ? FROM System' USING SiteID; IF OLDROW.SiteID <> SiteID THEN ABORT; END IF; END
Deviation | Details |
REFERENCING | The REFERENCING clause is not supported in ElevateDB and the old and new row values are always referred to as OLDROW and NEWROW. |
FOR EACH | The FOR EACH clause is not supported. ElevateDB triggers are always fired on a row basis and never on a statement basis. |
DESCRIPTION | The DESCRIPTION clause is an ElevateDB extension. |
This web page was last updated on Thursday, November 16, 2023 at 10:39 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |