B
B
BonBon Slick2021-01-09 13:39:00
SQL
BonBon Slick, 2021-01-09 13:39:00

Whether there is a sense vysheat foreign key for ER when all requests on pure SQL?

Since so many joins and so on go straight, that is

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;


That is, is there any point in hanging a foreign key
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)


after all, as I understand it, it is necessary for mapping entities in the code when it is.
For example Doctrine 2 and Entity
class User{
// foreign key post.owner_id on user.id
public $posts;
// foreign key comments.owner_id on user.id
public $comments;
}

To just do a join automatically.
$query->(User::class)->join(Post::class)

But I'm still wondering if there will be any boost to the speed or what other advantages?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman, 2021-01-09
@BonBonSlick

the foreign key is needed for what it is intended for. to guarantee referential integrity. the increase in the speed of sampling when linking tables is due to the index, which is created when a foreign key is specified.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question