DROP TRIGGER IF EXISTS `warning_after_ins_tr`;

CREATE TABLE `warning` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `iow_id` CHAR(30) NOT NULL DEFAULT 'unknown'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE `unit_fault` (
  `utf_id` INT NOT NULL AUTO_INCREMENT,
  `id` INT NOT NULL,
  PRIMARY KEY (`utf_id`),
  KEY `key_id` (`id`),
  FOREIGN KEY (`id`) REFERENCES `warning` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

DELIMITER ;;
CREATE OR REPLACE TRIGGER warning_after_ins_tr
AFTER INSERT ON `warning`
FOR EACH ROW BEGIN

    IF NEW.iow_id = 'TAMPER_TROUBLE' THEN
	SET @a := NEW.iow_id;
          INSERT INTO unit_fault SET id = NEW.id;
    END IF;
END;
