简体   繁体   English

如果从子表中删除行,则“在删除级联上”

[英]“On Delete Cascade” if deleting a row from the child table

I'm having a difficult time understanding "on delete cascade" If I had the following example: 我很难理解“删除级联”如果我有以下示例:

create table X (id int primary key, name char(10)); create table X(id int primary key,name char(10));

create table Y (bid int primary key, aid references A(id) on delete cascade); 创建表Y(bid int主键,辅助引用删除级联上的A(id));

X contains one row (111, 'Mike') X包含一行(111,'Mike')

Y contains two rows (1000, 111), (2000, 111)** Y包含两行(1000,111),(2000,111)**

I if removed row (2000,111) in table Y what would happen? 我如果在表Y中删除行(2000,111)会发生什么?

Would that row just be deleted or would it even allow me to delete anything because of the reference to the parent table? 该行是否会被删除,或者甚至允许我删除任何内容,因为引用了父表?

Thanks 谢谢

It would be deleted and nothing else would happen. 它将被删除,不会发生任何其他事情。 Cascading deletes only go from the referenced table to the referencing table. 级联删除仅从引用的表到引用表。 So a delete on table X will cascade a delete down to table y, while a delete on table y has no impact on table x. 因此,表X上的删除会将删除级联到表y,而表y上的删除对表x没有影响。

什么都不会发生,只有当你从表X中删除一行时,表Y中引用它的行才会被删除。

ON Delete cascade option wont effect anything if you perform any delete on the child table. 如果对子表执行任何删除,则“删除级联”选项不会生效。 This option is used to specify, when you delete a row in the parent table, the database server also deletes any rows associated with that row (foreign keys) in a child table. 此选项用于指定在删除父表中的行时,数据库服务器还会删除子表中与该行(外键)关联的所有行。 The principal advantage to the cascading-deletes feature is that it allows you to reduce the quantity of SQL statements you need to perform delete actions. 级联删除功能的主要优点是它允许您减少执行删除操作所需的SQL语句数量。

暂无
暂无

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

相关问题 Laravel Eloquant 删除子表行 - onDelete('cascade') 不删除子表行 - Laravel Eloquant Delete Child Table Row - onDelete('cascade') is not deleting child table row 如何调试mysql外键约束,ON DELETE CASCADE不能在生产环境中从子表中删除行 - How to debug mysql foreign key constraint, ON DELETE CASCADE not deleting rows from Child table on production environment 在子行删除父级删除CASCADE? - DELETE CASCADE on a child row delete parent? 如何编辑我的MySQL表,以便从父表中删除行不需要在子表行上进行级联删除? - How to edit my MySQL tables so that deleting row from parent doesn't require cascading delete on child table row? 查询删除级联在子表中不成功 - Query on delete cascade not success in child table 当父级被删除时,Mysql“级联删除”不会在外键行上删除 - Mysql 'Cascade On Delete' Not Deleting on Foreign Key Row When Parent Is Deleted MySQL,在删除级联上允许删除子表,为什么不在ON Update Cascade上不更新子表呢? - MySQL, On delete cascade is allowing to delete child table why not on ON Update Cascade will not update child table? Liquibase:onDelete="CASCADE" - 删除父项不会删除子项,但删除子项会删除父项 - Liquibase: onDelete="CASCADE" - deleting parent doesn't delete child, but deleting child deletes parent 如何从其他表中删除父行以及所有子行 - how delete parent row with all child row from other table 从表中删除行:“无法删除或更新父行:外键约束失败”是外键问题或CASCADE会完成这项工作吗? - Delete row from table:“Cannot delete or update a parent row:a foreign key constraint fails” is that a FOREIGN KEY problemm or CASCADE will do the job?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM