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));
创建表X (id int主键,name char(10)));
create table Y (bid int primary key, aid references A(id) on delete cascade);
创建表Y(投标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
谢谢
3 个解决方案
#1
3
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上的delete将级联到表y,而表y上的delete对表X没有影响。
#2
2
Nothing will happen, only if you delete a row from table X the rows in table Y referencing it will be deleted.
只有从表X中删除一行,引用该行的表Y中的行才会被删除。
#3
2
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.
在删除级联选项中,如果在子表上执行任何删除操作,则不会产生任何效果。此选项用于指定,当您删除父表中的一行时,数据库服务器还将删除与子表中的该行(外键)相关的任何行。cascading-deletes特性的主要优点是可以减少执行删除操作所需的SQL语句的数量。
#1
3
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上的delete将级联到表y,而表y上的delete对表X没有影响。
#2
2
Nothing will happen, only if you delete a row from table X the rows in table Y referencing it will be deleted.
只有从表X中删除一行,引用该行的表Y中的行才会被删除。
#3
2
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.
在删除级联选项中,如果在子表上执行任何删除操作,则不会产生任何效果。此选项用于指定,当您删除父表中的一行时,数据库服务器还将删除与子表中的该行(外键)相关的任何行。cascading-deletes特性的主要优点是可以减少执行删除操作所需的SQL语句的数量。