Is this work for mysql foreign keys?

In the past few years, I have read many articles on foreign keys in MySQL, but nothing recent. I know that they are good for use on something like a forum topic that has a child post, if I delete a topic with a message 100 related to this topic, foreign keys will make it delete those 100 topics for me, I’m still right then?

I am working on a social network in php / mysql, there is a user table with a user ID, then there are about 10 other tables that are associated with this table with this user ID field, should I use foreign keys on this? I will not need to update all tables, but, for example, if a user deletes this account, in the past I would run PHP as 10 delete requests, 1 for each table for the user. Is it good to use foreign keys?

+3
source share
5 answers

. , , . UserId 100 , UserId 100 users.

, Cascading Deletes , , , , . , , .

, , .

+3

, MySQL . , "CASCADE" MySQL , . "SET NULL" NULL, , , .

+1

, - , Foreign Key .

, , InnoDB on delete cascade (. 13.6.4.4. FOREIGN KEY), , .

+1

100 , 100 , ?

, . , , "" . , , , .

0

, , , , PHP 10 , 1 . ? ?

, . FK , , " ", , , , , , . , , CASCADE. , , FK, user_id .

http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

, MyISAM FK, . InnoDB .

0

Source: https://habr.com/ru/post/1727430/


All Articles