简体   繁体   English

INNODB,MySQL-多行的外键?

[英]INNODB, mysql - foreign key to multiple rows?

say that I have a table A like that: 说我有一个这样的表A:

[my id (primary key) (auto increment)] [other values]

and another table B like that 另一个像这样的表B

[my id (primary key)] [id of the row in table A] [other values]

can I use the foreign key to link all the rows of table B to the unique row in the table A? 如何使用外键将表B的所有行链接到表A中的唯一行? The goal is to force the CANCEL to all rows in table B if that row in table A is deletet. 目的是如果表A中的该行被删除,则强制取消表B中的所有行。

it would be possible to achieve the same result linking other tables similar to the B one, which contains multiple rows dependent of the unique row in table A? 链接类似于B的其他表可能会获得相同的结果,该表包含多行取决于表A中的唯一行?

I wasn't able to understand the guides in internet, so I ask here, where I know there are a lot of experts. 我无法理解互联网上的指南,所以我在这里问,我知道那里有很多专家。 thaks in advance. 提前解冻。

If you are asking about foreign key relationship in Mysql - innoDB tables. 如果您要询问Mysql-innoDB表中的外键关系。 Then yes if There is a table A having primary Key id 如果有一个具有主键ID的表A,则为是

If this key is used as Foreign Key in Table B and while specifying relationship in PhpMyAdmin Relation view of Table B. We need to specify ON DELETE CASCADE. 如果将此键用作表B中的外键,并且在表B的PhpMyAdmin关系视图中指定关系时使用。我们需要指定ON DELETE CASCADE。 So whenever a record in Table A will be deleted its corresponding child records in Table B will be deleted. 因此,每当删除表A中的记录时,表B中的相应子记录都将被删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM