我在SQLite下有一个表格如下:
CREATE TABLE "node" (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`namespace` TEXT NOT NULL,
`name` TEXT,
`parent_id` INTEGER DEFAULT NULL,
`str_value` TEXT DEFAULT NULL,
`int_value` INTEGER DEFAULT NULL,
FOREIGN KEY(parent_id) REFERENCES node(id) ON DELETE CASCADE
);
INSERT INTO `node` VALUES ('1','xxx','Parameter',NULL,NULL,NULL);
INSERT INTO `node` VALUES ('2','xxx','Info','1',NULL,NULL);
INSERT INTO `node` VALUES ('3','xxx','Daten','1',NULL,NULL);
INSERT INTO `node` VALUES ('4','xxx','Kennung','2',NULL,'100');
INSERT INTO `node` VALUES ('5','xxx','Version','2',NULL,'1');
INSERT INTO `node` VALUES ('6','xxx','Typ','2','AMIS',NULL);
INSERT INTO `node` VALUES ('7','xxx','Revision','2',NULL,'1');
执行时
delete from node where id=2;
由于DELETE CASCADE,我希望删除id = 4,5,6,7的节点。 但是,情况并非如此 - 仅删除id = 2。为什么呢?
BTW:加载DB文件后立即启用外键支持。
非常感谢, 迈克尔