title: CASCADE Delete mysql
body: <p>I'm creating a small 3-table database, essentially using it as a buffer for data, so it's using ENGINER = MEMORY. The database has the following structure:</p>
  
  <p><a href="https://i.stack.imgur.com/ttRgv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ttRgv.png" alt="The overview"></a></p>
  
  <p>I'm not that much into MySQL, so my question is: Is it possible to have a CASCADE DELETE, such that when I delete a MeassurementIteration, all MeassurementSet's and Meassurements that are coupled to the iteration will be deleted?</p>
  
  <p>The code:</p>
  
  <pre><code>-- 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.
  </code></pre>
  
  <p>Best regards.</p>