级联删除 mysql

CASCADE Delete mysql

我正在创建一个小型 3-table 数据库,本质上是将其用作数据缓冲区,因此它使用 ENGINER = MEMORY。数据库具有以下结构:

我不太喜欢 MySQL,所以我的问题是:是否可以进行级联删除,这样当我删除 MeassurementIteration 时,所有 MeassurementSet 和 Meassurements 都耦合到迭代会被删除吗?

代码:

-- Last modification date: 2017-04-03 08:09:06.263

-- tables
-- Table: Meassurement
CREATE TABLE Meassurement (
    id int NOT NULL AUTO_INCREMENT,
    msWay varchar(75) NOT NULL,
    qosClass int NOT NULL,
    timeReceived timestamp NOT NULL,
    timeReceivedFarEnd timestamp NOT NULL,
    timeSent timestamp NOT NULL,
    timeSentFarEnd timestamp NULL,
    seq int NOT NULL,
    MeassurementSet_id int NOT NULL,
    CONSTRAINT Meassurement_pk PRIMARY KEY (id)
) ENGINE MEMORY COMMENT 'Contains data for a single meassurement';

-- Table: MeassurementIteration
CREATE TABLE MeassurementIteration (
    id int NOT NULL AUTO_INCREMENT,
    start timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    end timestamp NULL,
    active bool NOT NULL,
    CONSTRAINT MeassurementIteration_pk PRIMARY KEY (id)
);

-- Table: MeassurementSet
CREATE TABLE MeassurementSet (
    id int NOT NULL AUTO_INCREMENT,
    avgDelayRT double NULL,
    avgDelayTR double NULL,
    avgRTD double NULL,
    maxDelayRT double NULL,
    maxDelayTR double NULL,
    maxRTD double NULL,
    minRTD double NULL,
    minDelayRT double NULL,
    minDelayTR double NULL,
    qosClass int NOT NULL,
    stdDev double NULL,
    stdDevRT double NULL,
    stdDevTR double NULL,
    msWay varchar(75) NOT NULL,
    MeassurementIteration_id int NOT NULL,
    CONSTRAINT MeassurementSet_pk PRIMARY KEY (id)
) ENGINE MEMORY COMMENT 'Contains a set of meassurements specific to a qosclass and Meassurementway';

-- foreign keys
-- Reference: MeassurementSet_MeassurementIteration (table: MeassurementSet)
ALTER TABLE MeassurementSet
    ADD CONSTRAINT MeassurementSet_MeassurementIteration 
    FOREIGN KEY MeassurementSet_MeassurementIteration (MeassurementIteration_id)
        REFERENCES MeassurementIteration (id) ON DELETE CASCADE;

-- Reference: Meassurement_MeassurementSet (table: Meassurement)
ALTER TABLE Meassurement 
    ADD CONSTRAINT Meassurement_MeassurementSet
    FOREIGN KEY Meassurement_MeassurementSet (MeassurementSet_id)
        REFERENCES MeassurementSet (id) ON DELETE CASCADE;

-- End of file.

此致。

您不能将 ON DELETE CASCADEENGINE = MEMORY 一起使用。 不支持外键。

这里有一个参考:(MySQL 文档)[https://dev.mysql.com/doc/refman/5.6/en/memory-storage-engine.html]

 Table 15.4 MEMORY Storage Engine Features
 ---------------------------------------------------
 Foreign key support    No

你也可以看看这个,另一个类似的问题。

SELECT table_nameenter 代码在这里 来自 referential_constraints 其中 constraint_schema = 'classicmodels'enter code here 和 referenced_table_name = 'buildings' 和 delete_rule = 'CASCADE'