Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
UPDATE RULES in Updating tables with referential constraints

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
jsnair

New User


Joined: 26 Sep 2006
Posts: 38
Location: India

PostPosted: Thu Jul 17, 2008 12:32 pm    Post subject: UPDATE RULES in Updating tables with referential constraints
Reply with quote

Hi All,

Could anybody please give me the right understanding for UPDATE RULES in Updating tables with referential constraints?

UPDATE NO ACTION
Specifies that the row in the parent table can be updated if no other row depends on it. If a dependent row exists in the relationship, the UPDATE fails. The check for dependent rows is performed at the end of the statement.

UPDATE RESTRICT
Specifies that the row in the parent table can be updated if no other row depends on it. If a dependent row exists in the relationship, the UPDATE fails. The check for dependent rows is performed immediately.


For the above 2 options only change I can see, will be the timing it performed the check for dependent row. Whether it is NO ACTION or RESTRICT if any dependent row exist the update fails and ultimately no updates in the table.

So what exactly the timing meana and when we can use those.

Could anybody explain me the scenario where we can use those?.
Back to top
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Jul 17, 2008 2:16 pm    Post subject:
Reply with quote

Jiji,

when using UPDATE NO ACTION , the only mandatory thing is that the value for the foreign key must be present in the parent table after update however, the value may not be the same as it was before the update operation occurred. ...

for eg.

Code:


TABLE1

EMPID   EMPNAME
---------------------
1           A
2           B
3           C

TABLE2 EMPNO REFERENCES TABLE1(EMPID) ON UPDATE NO ACTION

EMPNO
-------- 
1
2



now if im updating table1 ...

Code:


UPDATE TABLE1 SET EMPID = EMPID -1


This update wont fail because after update the value in table1 wud be 0,1,2 and this value will be referenced by table2 ... so this update will be successful ... it just ensures that the value for the foreign key of each row in the child table will have a matching value in the parent key of the corresponding parent table ...

but if TABLE2 was declared with a referential constraint ON UPDATE RESTRICT ... thsi update wudnt have happened ... because the value for the foreign key of each row in the child table will have the same matching value in the parent key of the parent table it had before the update operation was performed ....

ON UPDATE NO ACTION definition is used as the default referential constraint .. you need not mention this while creating the child table ..

Hope this is clear ....
Back to top
View user's profile Send private message
jsnair

New User


Joined: 26 Sep 2006
Posts: 38
Location: India

PostPosted: Thu Jul 17, 2008 5:41 pm    Post subject:
Reply with quote

Thanx very much...Ashimer..
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Jul 17, 2008 5:59 pm    Post subject:
Reply with quote

you're Welcome
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts Identify top 30 big tables or indexes... ashek15 DB2 0 Fri Jun 16, 2017 10:01 am
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts RULES(NOEVENPACK) in cobol jackzhang75 COBOL Programming 5 Wed Mar 29, 2017 12:47 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us