Foreign key constraints: When to use ON UPDATE and ON DELETE

后端 未结 3 1935
故里飘歌
故里飘歌 2020-12-04 04:22

I\'m designing my database schema using MySQL Workbench, which is pretty cool because you can do diagrams and it converts them :P

Anyways, I\'ve decided to use InnoD

3条回答
  •  悲哀的现实
    2020-12-04 04:58

    You'll need to consider this in context of the application. In general, you should design an application, not a database (the database simply being part of the application).

    Consider how your application should respond to various cases.

    The default action is to restrict (i.e. not permit) the operation, which is normally what you want as it prevents stupid programming errors. However, on DELETE CASCADE can also be useful. It really depends on your application and how you intend to delete particular objects.

    Personally, I'd use InnoDB because it doesn't trash your data (c.f. MyISAM, which does), rather than because it has FK constraints.

提交回复
热议问题