MYSQL CASCADE DELETE :级联删除。这个概念还是学习Oracle时得到的。
就是主键记录删除时,相关的有外键的表里的记录,也删除。
https://dev.mysql.com/doc/refman/5.7/en/delete.html
https://*.com/questions/2914936/mysql-foreign-key-constraints-cascade-delete
http://www.mysqltutorial.org/mysql-on-delete-cascade/
上面三个帖子解释的比较清楚。
另外CASCADE模式需要MYSQL引擎支持:Engine必须是InnoDB。
mysql> SHOW ENGINES;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set mysql>
一篇比较常用的两个引擎MyISAM和InnoDB的文章:
http://www.oschina.net/question/17_4248