Home > front end >  How foreign key is different from joins in SQL?
How foreign key is different from joins in SQL?

Time:04-11

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?

CodePudding user response:

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.

CodePudding user response:

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.

  • Related