外键定义服从下列情况:(前提条件)
1)
所有tables必须是InnoDB型,它们不能是临时表.因为在MySQL中只有InnoDB类型的表才支持外键.
2)
所有要建立外键的字段必须建立索引.
3)
对于非InnoDB表,FOREIGN KEY子句会被忽略掉。
https://blog.csdn.net/liqinghuan_blog/article/details/29214659
-- 双外键
INDEX (product_category, product_id),
FOREIGN KEY (product_category, product_id)
REFERENCES product(category, id)
ON UPDATE CASCADE ON DELETE RESTRICT,
-- 单外键
INDEX (customer_id),
FOREIGN KEY (customer_id)
REFERENCES customer(id)) TYPE=INNODB;
(6) 说明:
1.若不声明on update/delete,则默认是采用restrict方式.
2.对于外键约束,最好是采用: ON UPDATE CASCADE ON DELETE RESTRICT 的方式.