472,982 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 software developers and data experts.

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 6621
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.uni-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.uni-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
by: Sean Utt | last post by:
Table "grps" Column | Type | Modifiers -------------+-----------------------------+-------------------------------- --------------------- grpsid ...
1
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...
14
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...
1
by: db2admin | last post by:
Hello, I lack knowledge about triggers. I have created trigger on table A Table A ------------------------------------------------- ID INTEGER CASEID ...
9
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,...
2
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...
0
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...
9
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...
3
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.