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

UPDATE RULES in Updating tables with referential constraints


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Need to fetch data from so many DB2 t... DB2 9
No new posts Updating a 1 byte thats in occurs mul... DFSORT/ICETOOL 6
No new posts Read a flat file and update DB2 table JCL & VSAM 2
No new posts how to update an ISR appl var from an... TSO/ISPF 8
No new posts How to: PK does not exist in several ... DB2 6
Search our Forums:

Back to Top