本文介绍了MySQL:在简单表"id | parent | text"的ON UPDATE CASCADE上,不可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张下表:
CREATE TABLE IF NOT EXISTS `Tree` (
`id` int(10) NOT NULL,
`parent` int(10) DEFAULT NULL,
`text` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `parent` (`parent`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `Tree` (`id`, `parent`, `text`) VALUES
(1, 1, '1'),
(2, 1, '1.1'),
(3, 1, '1.2'),
(4, 1, '1.3');
ALTER TABLE `Tree` ADD CONSTRAINT `tree_ibfk_1` FOREIGN KEY (`parent`) REFERENCES `tree` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
执行完所有上述语句后,发现以下问题:
After having executed all of the above statements a problem observed for the following one:
UPDATE `Tree` SET `id` = '10' WHERE `Tree`.`id` = 1
尽管由于ON UPDATE CASCADE
约束,预期更改主ID将导致所有链接的parent
记录自动更新.这些级联的参照完整性约束不是全部吗?
While it is expected that changing the main id would cause all linked parent
records to update automatically due to ON UPDATE CASCADE
constraint. Aren't these cascading referential integrity constraints are all about?
推荐答案
文档说以下内容(强调我的意思):
The docs say the following (emphasis mine):
这篇关于MySQL:在简单表"id | parent | text"的ON UPDATE CASCADE上,不可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!