我正在創建一個小型的3表數據庫,基本上使用它作爲數據的緩衝區,所以它使用的是ENGINER = MEMORY。該數據庫具有以下結構:級聯刪除mysql
我沒有那麼多到MySQL,所以我的問題是:是否有可能有級聯刪除,這樣,當我刪除MeassurementIteration,所有MeassurementSet的和與迭代相關的度量將被刪除?
代碼:
-- 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.
最好的問候。
http://www.mysqltutorial.org/mysql-上刪除級聯/ – scaisEdge