Why do I need to use foreign key if I can use WHERE?

前端 未结 10 1416
难免孤独
难免孤独 2020-12-23 16:34

A beginners\' question about foreign key in MySQL.

In w3school it says,

A FOREIGN KEY in one table points to a PRIMARY KEY in another table.<

10条回答
  •  青春惊慌失措
    2020-12-23 17:14

    The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables.

    The FOREIGN KEY constraint also prevents invalid data from being inserted into the foreign key column, because it has to be one of the values contained in the table it points to.

提交回复
热议问题