测试数据:
有一个表aritcle和另一个表article_comment,关联是article的id。
创建测试表及添加测试数据:
表1:
复制代码 代码示例:
CREATE TABLE `article` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
表2:
复制代码 代码示例:
CREATE TABLE `article_comment` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`text` varchar(200) NOT NULL,
`article_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `art_id` (`article_id`),
CONSTRAINT `art_id` FOREIGN KEY (`article_id`) REFERENCES `article` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
添加测试数据:
复制代码 代码示例:
set sql_mode=