473,569 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trigger updating another table gives SQL0206N

Hi All,

I am trying to a get a trigger retrieved from Oracle to work on DB2
UDB 8.1. I am getting the following error when trying to create the
trigger. How would I resolve this?

create table dept (
dept# int not null primary key,
deptname varchar(30))
@

create table rep (
rep# int not null primary key,
dept# int ,
repname varchar(30))
@

create trigger brd_dept no cascade
before delete on dept
for each row
mode db2sql
begin atomic
--similar to cascade set null
update rep set dept# = null where dept# = old.dept#;
end
@

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0206N "OLD.DEPT#" is not valid in the context where it is used.
LINE
NUMBER=7. SQLSTATE=42703

thanks,
Nov 12 '05 #1
3 6649
Prince Kumar <gs**@yahoo.com > wrote:
Hi All,

I am trying to a get a trigger retrieved from Oracle to work on DB2
UDB 8.1. I am getting the following error when trying to create the
trigger. How would I resolve this?

create table dept (
dept# int not null primary key,
deptname varchar(30))
@

create table rep (
rep# int not null primary key,
dept# int ,
repname varchar(30))
@

create trigger brd_dept no cascade
before delete on dept
You need to specify a correlation name for OLD here like this:

REFERENCING OLD AS old
for each row
mode db2sql
begin atomic
--similar to cascade set null
update rep set dept# = null where dept# = old.dept#;
end
@


You can also not update the other table in a BEFORE trigger, so use an AFTER
trigger instead.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2
Thanks for the response.

I don't think neither of the above solutions work for me.

1, referencing OLD as old is the default and hence I do not need to
explicitly specify.

2, I must use before trigger. The trigger I posted is a simple sample.
I have many such oracle before triggers (insert/update etc), I want to
convert. All of them gives the same error. May be there is a simple
way of rewriting them.

Thanks,

Knut Stolze <st****@de.ibm. com> wrote in message news:<bn******* ***@fsuj29.rz.u ni-jena.de>...
Prince Kumar <gs**@yahoo.com > wrote:
Hi All,

I am trying to a get a trigger retrieved from Oracle to work on DB2
UDB 8.1. I am getting the following error when trying to create the
trigger. How would I resolve this?

create table dept (
dept# int not null primary key,
deptname varchar(30))
@

create table rep (
rep# int not null primary key,
dept# int ,
repname varchar(30))
@

create trigger brd_dept no cascade
before delete on dept


You need to specify a correlation name for OLD here like this:

REFERENCING OLD AS old
for each row
mode db2sql
begin atomic
--similar to cascade set null
update rep set dept# = null where dept# = old.dept#;
end
@


You can also not update the other table in a BEFORE trigger, so use an AFTER
trigger instead.

Nov 12 '05 #3
Prince Kumar <gs**@yahoo.com > wrote:
Thanks for the response.

I don't think neither of the above solutions work for me.

1, referencing OLD as old is the default and hence I do not need to
explicitly specify.
Hmmm... where did you find that information? In the SQL Reference I use I
cannot find anything stating that REFERENCING OLD AS old would be the
default. So I believe you might be mistaken.
2, I must use before trigger. The trigger I posted is a simple sample.
I have many such oracle before triggers (insert/update etc), I want to
convert. All of them gives the same error. May be there is a simple
way of rewriting them.
Why exactly do you need this to be a BEFORE trigger? What's the technical
reason?
Knut Stolze <st****@de.ibm. com> wrote in message
news:<bn******* ***@fsuj29.rz.u ni-jena.de>...
Prince Kumar <gs**@yahoo.com > wrote:
> Hi All,
>
> I am trying to a get a trigger retrieved from Oracle to work on DB2
> UDB 8.1. I am getting the following error when trying to create the
> trigger. How would I resolve this?
>
> create table dept (
> dept# int not null primary key,
> deptname varchar(30))
> @
>
> create table rep (
> rep# int not null primary key,
> dept# int ,
> repname varchar(30))
> @
>
> create trigger brd_dept no cascade
> before delete on dept


You need to specify a correlation name for OLD here like this:

REFERENCING OLD AS old
> for each row
> mode db2sql
> begin atomic
> --similar to cascade set null
> update rep set dept# = null where dept# = old.dept#;
> end
> @


You can also not update the other table in a BEFORE trigger, so use an
AFTER trigger instead.


--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #4

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

Similar topics

0
4086
by: Sean Utt | last post by:
Table "grps" Column | Type | Modifiers -------------+-----------------------------+-------------------------------- --------------------- grpsid | integer | not null default nextval('"grps_grpsid_seq"'::text) grpsname | text | not null...
1
7228
by: Rebecca Lovelace | last post by:
I have a trigger on a table. I am trying to dynamically log the changed fields on the table to another table, so I am iterating through the bits in COLUMNS_UPDATED() to find what's changed, and getting the column name programatically. This is all working fine. If I do a regular insert command in my trigger then everything works fine. ...
14
47871
by: John | last post by:
Hi all, I am doing the change from having worked in Oracle for a long time to MS SQL server and am frustrated with a couple of simple SQL stmt's. Or at least they have always been easy. The SQL is pretty straightforward. I am updating a field with a Max effective dated row criteria. (PepopleSoft app) update PS_JOB as A set BAS_GROUP_ID...
1
8982
by: db2admin | last post by:
Hello, I lack knowledge about triggers. I have created trigger on table A Table A ------------------------------------------------- ID INTEGER CASEID INTEGER CEID INTEGER AS_CD CHAR(2)
9
9299
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger, with the exception of the table name. I could manually change the table name in the trigger and create it, over and over, but I'd like to automate...
2
2589
by: graju80 | last post by:
Hey Gurus..I am trying to figures out where my syntax is incorrect in the following SQL to to create an after insert trigger... I am getting SQL0206N "INSERTROW.MF_USERID" is not valid in the context where it is used. LINE NUMBER=1. SQLSTATE=42703 CREATE TRIGGER "O000634"."test_insert" AFTER INSERT ON "O000634"."TMAX300_USER" ...
0
1491
by: KiranKGone | last post by:
Hello All, I need to define a trigger for updating the multiple columns of a target table when an insert happens on a subject table. I have written the following trigger, however, getting the following errors. CREATE TRIGGER T_DASHBOARD AFTER UPDATE ON REQ_GRP_REC REFERENCING OLD_TABLE AS O NEW_TABLE AS N
9
1982
by: Chico Che | last post by:
Have a table that has following fields (pkid, field1, field2, field3, field4). I need to create a trigger that will insert a row into another table with the pkid column that was updated. Any help will be appreciated.
3
1636
by: lenygold via DBMonster.com | last post by:
Hi everybody! I have an INSERT stattement like this: insert into ELIGIBLE_PAY select from ELIGIBLE_PAY_B where cust_id = 999999; after insert i would like to delete row from source table by creating the following TRIGGER:
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7678
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7982
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.