Do you absolutely need foreign keys in a database?

后端 未结 11 998
遥遥无期
遥遥无期 2021-02-12 20:31

I was wondering how useful foreign keys really are in a database. Essentially, if the developers know what keys the different tables depend on, they can write the queries just

11条回答
  •  伪装坚强ぢ
    2021-02-12 21:24

    If you don't care about referential integrity then you are right. But.... you should care about referential integrity.

    The problem is that people make mistakes. Computers do not.

    Regarding your comment:

    but say for example, the programmers do a good job of preserving data integrity

    Someone will eventually make a mistake. No one is perfect. Also if you bring someone new in you aren't always sure of their ability to write "perfect" code.

    In addition to that you lose the ability to do cascading deletes and a number of other features that having defined foreign keys allow.

提交回复
热议问题