引用我有兩個表:MySQL的REPLACE行爲不同於更新,如果主鍵是由外鍵
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;
如果我的類別表(1行)進行REPLACE
那麼所有的條目在事件表中引用類別表中的修改行將被丟棄。
但是,如果我在類別表UPDATE
一排,然後在事件表中的條目保持不變。
爲什麼這種行爲,爲什麼當我REPLACE
什麼東西所有引用該列的條目都被丟棄?
我試着用ON UPDATE CASCADE
和默認的相同的行爲。
Google無法幫助我。