mysql外键概念 [英] mysql foreign key concept

查看:138
本文介绍了mysql外键概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CREATE TABLE parent (id INT NOT NULL,
                     PRIMARY KEY (id)
) ENGINE=INNODB;


CREATE TABLE child (id INT, parent_id INT,
                    INDEX par_ind (parent_id),
                    FOREIGN KEY (parent_id) REFERENCES parent(id)
                      ON DELETE CASCADE
) ENGINE=INNODB;

我不明白将ENGINE = INNODB放在这里的含义,为什么我们使用ON DELETE CASCADE?

I dont understand the meaning of putting ENGINE = INNODB here, and why do we use ON DELETE CASCADE?

推荐答案

engine = innodb将确保您获得外键支持.默认的MyISAM引擎不支持外键.如果删除了父表中的引用行,则在删除时级联将删除子行.

engine=innodb will ensure you get foreign key support. The default MyISAM engine doesn't support foreign keys. On delete cascade will remove the child row if the referenced row in the parent table is removed.

这篇关于mysql外键概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆