[英]“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.