这是Mysql外键的工作吗?(Is this a job for Mysql Foreign Keys?)
在过去的几年里,我已经阅读了很多关于MySQL中外键的文章,但最近没有。 我知道他们很高兴使用类似论坛主题的东西,如果我删除了一个主题,其中有100个帖子连接到该主题,外键会让它删除这100个主题,我到目前为止是正确的?
我正在使用php / mysql中的社交网络,有一个带有用户ID的用户表,那么有大约10个其他表通过该用户ID字段连接到该表,我应该使用外键吗? 我不需要更新所有表,但是例如,如果用户删除了那个帐户,过去我会让PHP运行像10个删除查询,每个表上有1个用户。 这听起来像是使用外键的好工作吗?
In the past few years I have read plenty of articles on Foreign Keys in MySQL, nothing recent though. I know they are good to use on something like a forum topic that has child post's under it, if I delete a topic with 100 post's connected to that topic, foreign keys will make it delete those 100 topics for me, am I correct so far?
I'm working on a social network in php/mysql, there is a user table with a user ID then there is about 10 other tables that are connected to that table by that User ID field, should I be using foreign keys on this? I won't ever need to update all the tables but for example if a user deletes there account, in the past I would have the PHP run like 10 delete queries, 1 on each table for the user. Does this sound like a good job to be using Foreign Keys on?
原文:https://stackoverflow.com/questions/2009969