Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011
    Posts
    5

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •