CREATE TABLE `rehab_macaddress` (
  `Mac` varchar(255) NOT NULL,
  `Model` varchar(255),
  `Type` varchar(255),
  `Name` varchar(255),
  `Tag` varchar(255),
  `Version` varchar(255),
  `Username` varchar(255) NOT NULL DEFAULT "",
  `License` varchar(255),
  `Active` tinyint(1) NOT NULL DEFAULT 1,
  `EditedBy` bigint(20),
  `Checksum` varchar(32),
  `Last_Edit` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`MAC`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `rehab_macaddress_backup` (
  `Backup_ID` int(9) NOT NULL AUTO_INCREMENT,
  `Mac` varchar(255) NOT NULL,
  `Model` varchar(255),
  `Type` varchar(255),
  `Name` varchar(255),
  `Version` varchar(255),
  `Username` varchar(255) NOT NULL DEFAULT "",
  `License` varchar(255),
  `Active` tinyint(1) NOT NULL DEFAULT 1,
  `EditedBy` bigint(20),
  `Checksum` varchar(32),
  `Previous_Last_Edit` timestamp NULL DEFAULT NULL,
  `Last_Edit` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`Backup_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
DROP TRIGGER IF EXISTS `MacAddress_Backup`;
DELIMITER //
CREATE TRIGGER `MacAddress_Backup` AFTER UPDATE ON `rehab_macaddress`
 FOR EACH ROW
  BEGIN
	INSERT INTO `rehab_macaddress_backup`(`Mac`,`Model`,`Type`,`Name`,`Version`,`Username`,`License`,`Active`,`EditedBy`,`Checksum`,`Previous_Last_Edit`) VALUES (OLD.`Mac`,OLD.`Model`,OLD.`Type`,OLD.`Name`,OLD.`Version`,OLD.`Username`,OLD.`License`,OLD.`Active`,OLD.`EditedBy`,OLD.`Checksum`,OLD.`Last_Edit`);
  END
// DELIMITER ;