当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - why use foreign key to my tables when i can achieve that with sql joins?

问题描述:

my question is what the purpose of using relations between tables , when i can achieve that with joining tables with sql joins ?

网友答案:

Foreign Keys give another layer of safety. They provide data integrity on data level. They prevent you from adding a record which does not fulfill the relation.

For example, if you have a table users with three Users (IDs 1, 2 and 3) and another table entries, where entries.uid has a relation to users.id, this means you can't add an entry to entries where you would add an entry.uid of 4, if you don't have an user with ID 4 defined.

分享给朋友:
您可能感兴趣的文章:
随机阅读: