Foreign Keys vs Joins

前端 未结 2 2052
不思量自难忘°
不思量自难忘° 2020-12-23 16:44

Is it better to use foreign keys in tables or can the same results be achieved with joins?

2条回答
  •  心在旅途
    2020-12-23 17:48

    FOREIGN KEYs and JOINs don't do the same thing!

    • A FOREIGN KEY enforces data integrity, making sure the data confirms to some rules when it is added to the DB.
    • A JOIN is used when you extract/query data from the DB by giving rules how to select the data.

    • JOINs work if there are FK or not.

    • FK's work if you extract data with or without JOINs.

    CONCLUSION: FK and JOIN don't allow you to achieve the same goal!

提交回复
热议问题