我有两个表格:
CREATE TABLE `category` (
`category_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` mediumint(8) unsigned NOT NULL,
`name` varchar(20) CHARACTER SET ascii NOT NULL,
`description` varchar(100) DEFAULT NULL,
`repeat_interval` tinyint(3) unsigned NOT NULL DEFAULT 0 ,
`color` mediumint(8) unsigned NOT NULL,
PRIMARY KEY (`category_id`),
KEY `id` (`user_id`),
CONSTRAINT `category_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `event` (
`event_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`category_id` int(10) unsigned NOT NULL,
`name` varchar(20) CHARACTER SET ascii NOT NULL,
`description` varchar(100) DEFAULT NULL,
`repeat_interval` tinyint(3) unsigned NOT NULL DEFAULT 0 ,
`color` mediumint(8) unsigned NOT NULL,
`priority` tinyint(3) unsigned NOT NULL DEFAULT 0 ,
`start` timestamp NOT NULL DEFAULT 0000-00-00 00:00:00 ,
`end` timestamp NOT NULL DEFAULT 0000-00-00 00:00:00 ,
`done` tinyint(1) NOT NULL DEFAULT 0 ,
PRIMARY KEY (`event_id`),
KEY `category_id` (`category_id`),
CONSTRAINT `event_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `category` (`category_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
If I make a REPLACE
in the category table (one row) then all the entries in the event table referencing the modified row in the category table will be discarded.
But if I UPDATE
a row in the category table then the entries in the event table are left untouched.
为什么这一行为,为什么在IREPLACE
时,所有条目都提到该栏被丢弃?
I tried with both ON UPDATE CASCADE
and the default, same behaviour.
谷歌可以帮助我。