0

Is there any reason to use an ON UPDATE constraint in a database if you will never ever change an ID (better said: primary key field)?

stofl
  • 2,950
  • 6
  • 35
  • 48
  • Check this link may help you http://stackoverflow.com/questions/1481476/when-to-use-on-update-cascade – Mayank Pandya Apr 08 '13 at 16:16
  • Thank you. Seems, that there is no reason (if IDs don't change). The answer with the clubs/bands/concerts is bad database design, I would say. – stofl Apr 08 '13 at 16:34

1 Answers1

0

InnoDB permits a foreign key to reference any index column or group of columns. Therefore, only if you never change a referenced field (as opposed to a primary key), then you can ignore this issue.

Other than that, don't use it if you don't need it.

Side remark: the default behaviour (i.e. if you omit the ON UPDATE clause) is to reject any update on the referenced field, preventing you from unknowingly breaking the referential integrity.

RandomSeed
  • 29,301
  • 6
  • 52
  • 87
  • Thanks. I think a *referenced field* should always be a primary key or a part of it in n:m relation tables, right? – stofl Apr 08 '13 at 16:39
  • 1
    @stofl Yes, I can think of no case where a surrogate key (the most frequent type of primary key) would need to be updated. However, let me refer you to [this answer](http://stackoverflow.com/a/1481611/1446005). – RandomSeed Apr 09 '13 at 08:09