title: When to use "ON UPDATE CASCADE"
body: <p>I use <code>ON DELETE CASCADE</code> regularly but I never use <code>ON UPDATE CASCADE</code> as I am not so sure in what situation it will be useful.</p>
  <p>For the sake of discussion let see some code.</p>
  <pre><code>CREATE TABLE parent (
      id INT NOT NULL AUTO_INCREMENT,
      PRIMARY KEY (id)
  );
  
  CREATE TABLE child (
      id INT NOT NULL AUTO_INCREMENT, parent_id INT,
      INDEX par_ind (parent_id),
      FOREIGN KEY (parent_id)
          REFERENCES parent(id)
          ON DELETE CASCADE
  );
  </code></pre>
  <p>For <code>ON DELETE CASCADE</code>, if a parent with an <code>id</code> is deleted, a record in child with <code>parent_id = parent.id</code> will be automatically deleted. This should be no problem.</p>
  <ol>
  <li><p>This means that <code>ON UPDATE CASCADE</code> will do the same thing when <code>id</code> of the parent is updated?</p>
  </li>
  <li><p>If (1) is true, it means that there is no need to use <code>ON UPDATE CASCADE</code> if <code>parent.id</code> is not updatable (or will never be updated) like when it is <code>AUTO_INCREMENT</code> or always set to be <code>TIMESTAMP</code>. Is that right?</p>
  </li>
  <li><p>If (2) is not true, in what other kind of situation should we use <code>ON UPDATE CASCADE</code>?</p>
  </li>
  <li><p>What if I (for some reason) update the <code>child.parent_id</code> to be something not existing, will it then be automatically deleted?</p>
  </li>
  </ol>
  <p>Well, I know, some of the question above can be test programmatically to understand but I want also know if any of this is database vendor dependent or not.</p>
  <p>Please shed some light.</p>