473,503 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DB2 Trigger syntax

Hi,

I'm new to DB2 from SQL Server, There's a problem with the syntax
below, is anyone able to see what the issue is? Do I have too many
semi colans?

CREATE TRIGGER AUDIT
AFTER UPDATE ON ABEFORE
REFERENCING OLD AS O
FOR EACH ROW MODE DB2SQL
WHEN ('YES' IN SELECT CONTROLFLAG FROM TRIGGERCONTROL WHERE
TRIGGERNAME = 'AUDIT')
BEGIN ATOMIC
INSERT INTO AAFTER (AAFTERID,NAME,TIMESTAMP) VALUES
(O.ABEFOREID,O.NAME,CURRENT TIMESTAMP);
END;

I have a table called ABEFORE and a table called AAFTER, the insert
statement works fine when I pass in 1,'TEST' CURRENT TIMESTAMP

Any help would be appreciated.

Jun 20 '07 #1
2 5650
On Jun 20, 3:13 pm, Chappy <jamieca...@gmail.comwrote:
Hi,

I'm new to DB2 from SQL Server, There's a problem with the syntax
below, is anyone able to see what the issue is? Do I have too many
semi colans?

CREATE TRIGGER AUDIT
AFTER UPDATE ON ABEFORE
REFERENCING OLD AS O
FOR EACH ROW MODE DB2SQL
WHEN ('YES' IN SELECT CONTROLFLAG FROM TRIGGERCONTROL WHERE
TRIGGERNAME = 'AUDIT')
BEGIN ATOMIC
INSERT INTO AAFTER (AAFTERID,NAME,TIMESTAMP) VALUES
(O.ABEFOREID,O.NAME,CURRENT TIMESTAMP);
END;

I have a table called ABEFORE and a table called AAFTER, the insert
statement works fine when I pass in 1,'TEST' CURRENT TIMESTAMP

Any help would be appreciated.
There generally seems to be a problem with me using BEGIN ATOMIC

Jun 20 '07 #2
There generally seems to be a problem with me using BEGIN ATOMIC
Indeed.
First there is a typo ABEFORE should be A BEFORE. Perhaps a copy-paste
in the post.
You main problem is that by default the CLP treats ";" very much like
"GO" and that conflicts with the ";' which is part of the SQL PL language.

You can change the termination character in the clp with db2 -td@ (to
set it to "@"). In the GUI there is a setting either in the preferences
pane or somewhere on the pane of the editor itself.
In DB2 9 I think multi character terminators are also supported. So you
could use GO for convenience.

Within a script or CLP I liek to change teh terminator before each
CREATE PROCEDURE/TRIGGER/FUNCTION with:
--#SET TERMINATOR @
CREATE TRIGGER ...
BEGIN ATOMIC
....
END
@
--#SET TERMINATOR ;

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
8010
by: Fernand St-Georges | last post by:
Hi, can someone tell how to write a Trigger; I am familiar with Sybase Sql Anywhere trigger syntax. Actually I have three tables MEMBER, CONTRACT and PAYMENT I need to update the MEMBER.BALANCE...
2
1580
by: William F. O'Neill | last post by:
Am using SQL Server 2000 on WINXP Pro. Have a requirement to change some Oracle triggers to SQL 2000. I have modied this one Insert Trigger, but get an error when I attempt to compile: CREATE...
4
1561
by: nosbtr1 | last post by:
When a row gets modified and it invokes a trigger, we would like to be able to update the row that was modified inside the trigger. This is (basically) how we are doing it now: CREATE TRIGGER...
33
4736
by: coosa | last post by:
I have a table: ---------------------------------------------------- CREATE TABLE CATEGORY ( CATEGORY_ID INTEGER IDENTITY(1,1) NOT NULL, CATEGORY_NAME VARCHAR(40) NOT NULL,...
12
4737
by: Bob Stearns | last post by:
I am trying to create a duplicate prevention trigger: CREATE TRIGGER is3.ard_u_unique BEFORE UPDATE OF act_recov_date ON is3.flushes REFERENCING NEW AS N FOR EACH ROW MODE DB2SQL WHEN...
5
3277
by: Bob Stearns | last post by:
I have two (actually many) dates in a table I want to validate on insertion. The following works in the case of only one WHEN clause but fails with two (or more), with the (improper?...
3
2081
by: Axel | last post by:
Hello, I have detail sections in several subforms that are used to fill daily order data per product. Each row contains textboxes for the weekdays and a locked textbox (txtTotal) for the week's...
1
2191
by: deepdata | last post by:
Hi, I am creating a trigger in DB2 express version. When i use the following syntax to create trigger CREATE TRIGGER USER_PK_TRIGGER BEFORE INSERT On users REFERENCING NEW As N FOR EACH...
6
3607
by: Jchick | last post by:
Im a newbie with a sql table in a MSDE database that contains fields of CustName, BrokerName, Type, Status. I am trying to write a trigger that does this: 1. When a new record in a table is...
4
2103
zachster17
by: zachster17 | last post by:
Hello all, I have 2 tables (tblAddProviderProfessional and tblAddProvider). There are other tables such as tblAddProviderFacility and so forth. tblAddProvider is a table that has similar data...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.