外键与在SQL中的加入有何不同?
我已经使用 JOINS 很长一段时间了,不知道外键如何影响 JOIN。我想知道他们有什么不同?如果其中一个缺席,是否会影响另一个?
I have been using JOINS for a long period of time and don't know how foreign keys affect JOINs. I want to know how they are different? If one is absent, does it affect the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JOIN计算一个由联合表的行组合的行组成的表。外键在两个表之间执行一致性。两者都是完全不同的概念,并且彼此无关,即使您通常最终会加入与外键约束相关的列。
也就是说,外键的存在可能会影响优化器如何估计某些连接的结果,因为它提供了其他信息。但这取决于您正在使用的数据库软件。
A join calculates a table that consists of a rows combined from the rows of the joined tables. A foreign key enforces consistency between two tables. Both are entirely different concepts and have nothing to do with each other, even though you will often end up joining on columns that are related by a foreign key constraint.
That said, the existence of a foreign key may influence how the optimizer estimates the results of certain joins, since it provides additional information. But that will depend on the database software you are using.
JOIN 是一种条件,用于确定一个表中的某些行是否与另一个表中的某些行匹配,以及这些行对是否必须作为一个组合行进行处理。
FOREIGN KEY 是数据一致性检查子系统的规则,用于在任何数据更改后检查数据状态以确保最终数据状态的有效性。
JOIN 和 FK 之间没有任何共同点。
JOIN is a condition which determines does some row from one table matches some row in another table and does these rows pair must be processed as one combined row.
FOREIGN KEY is a rule for data consistency checking subsystem which checks the data state after any data change for final data state validity.
There is nothing in common between JOIN and FK.