Do you absolutely need foreign keys in a database?

后端 未结 11 1576
孤城傲影
孤城傲影 2021-02-12 20:48

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

    Folks have offered up some good answers above. However, one important point I didn't see mentioned is that foreign keys make your entity relationship diagrams (ERDs) easier to generate and much more meaningful. Without FKs, you either need to depict the FK relationships on your ERD manually (painful for you) or not at all (painful for others, and perhaps even for yourself once your memory of the implied FK relationships starts to fade over time). With FKs explicitly defined, most tools that automatically generate ERDs from database object definitions will automatically detect and depict the FK relationships. I hope this helps.

提交回复
热议问题