If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > ON UPDATE CASCADE and Delete operations

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-12-11, 08:04
krisdotca krisdotca is offline
Registered User
 
Join Date: Mar 2011
Posts: 5
ON UPDATE CASCADE and Delete operations

I'm new to the ON DELETE and ON UPDATE options for foreign keys and am trying to make sure I understand their behaviour.

If I define a foreign key using ON UPDATE CASCADE what happens if the corresponding row in the parent table is deleted? Does it function similar to ON DELETE SET NULL and set the value of the column to NULL? If not, can I use
"ON DELETE SET NULL ON UPDATE CASCADE" to ensure that both updates and deletes are handled properly?


Cheers, Kris
Reply With Quote
  #2 (permalink)  
Old 03-12-11, 08:25
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Quote:
Originally Posted by krisdotca View Post
If I define a foreign key using ON UPDATE CASCADE what happens if the corresponding row in the parent table is deleted?
nothing

ON UPDATE defines what happens when the corresponding key in the parent table is updated

Quote:
Originally Posted by krisdotca View Post
If not, can I use
"ON DELETE SET NULL ON UPDATE CASCADE" to ensure that both updates and deletes are handled properly?
only if those (set null and cascade, respectively) are the proper actions that you want done in the case of deletes or updates

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On