IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Query on DB2 Triggers


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
srinut123

New User


Joined: 11 Oct 2005
Posts: 62
Location: India

PostPosted: Tue Apr 20, 2010 9:53 am
Reply with quote

Hi
I've a requirement..

When An insert or delete happens on table A,
-> if A.Field 1 is avalable in Table "B",
--> check if A.Field 2 is available in Table "C".. If INSERT, insert it into table "C" .. if "DELETE", delete it from table "C".

Can we accomplish this with DB2 triggers? I'm poor in this..

Thanks
Sri
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Apr 20, 2010 10:17 am
Reply with quote

Hello,

What does available mean in this question?

It will probably help if a more "real" example is shown rather than alphabet soup.

Database activity can activate a trigger, but i am not sure how to relate this to the "availability" of these "fields" (columns maybe?).
Back to top
View user's profile Send private message
srinut123

New User


Joined: 11 Oct 2005
Posts: 62
Location: India

PostPosted: Tue Apr 20, 2010 11:22 am
Reply with quote

Hi
Here is an example..

Code:
TABLE A:

COMP LOC-ID   DESC  FILED 3 FIELD 4 ...
A100 9991221  TEST1  X        X
A100 9991223  TEST1  X        X
A101 8991221  TEST1  X        X
A101 8991222  TEST1  X        X



TABLE B:

COMP TYPE
A100  1
A101  2
A103  3


TABLE C:

COMP    LOCID    FILED 5 FIELD 6
A100    9991221  X        X
A100    9991222  X        X
A101    8991221  X        X
A101    8991222  X        X


COMP code and LOCID in Table C should be available in Table "A"..
There is no problem when we do an initial load.. but in the future, if a LOCID is inserted or deleted from Table "A",

if COMP associated with LOCID inserted or deleted is in Table "B", then we have to insert/delete that into Table "C" (getting data for Field5 and Field 6 from other tables).. if COMP associated with LOCID inserted or deleted is not in Table "B".. we can just ignore it..

I wanted to check if it is possible to do this thru Triggers.. as we dont want to go for a new program and schedule another job..

Thanks
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Apr 20, 2010 11:43 am
Reply with quote

what you mean by available is constraints.

by your vocabulary, it is obvious that you have not bothered to read the manual.

the answer to you question - can it be done by triggers - yes.

how to do it can be found in the following:

DB for z/OS Application Programming Topics

a list of 23 Redbooks that are applicable

Application programmers manual and SQL Reference for the db2 version that you are using

An Article about creating DB2 Triggers
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top