mysql innodb 删除_如何删除MySQL InnoDB中的所有相关记录?

如果要在主表中删除记录时自动删除相关记录,则需要在外键上指定ON DELETE CASCADE。

根据手册,您选择对外键的约束是其中之一:

CASCADE: Delete or update the row from the parent table, and

automatically delete or update the matching rows in the child table.

Both ON DELETE CASCADE and ON UPDATE CASCADE are supported. Between

two tables, do not define several ON UPDATE CASCADE clauses that act

on the same column in the parent table or in the child table.

Note Currently, cascaded foreign key actions do not activate triggers.

SET NULL: Delete or update the row from the parent table, and set the

foreign key column or columns in the child table to NULL. Both ON

DELETE SET NULL and ON UPDATE SET NULL clauses are supported.

If you specify a SET NULL action, make sure that you have not declared

the columns in the child table as NOT NULL.

RESTRICT: Rejects the delete or update operation for the parent table.

Specifying RESTRICT (or NO ACTION) is the same as omitting the ON

DELETE or ON UPDATE clause.

NO ACTION: A keyword from standard SQL. In MySQL, equivalent to

RESTRICT. InnoDB rejects the delete or update operation for the parent

table if there is a related foreign key value in the referenced table.

Some database systems have deferred checks, and NO ACTION is a

deferred check. In MySQL, foreign key constraints are checked

immediately, so NO ACTION is the same as RESTRICT.

默认情况下,如果您没有指定任何内容,则为NO ACTION - 这就是您删除现在没有做任何事情的原因。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值