

-- Dumping database structure for mg_genesis
CREATE DATABASE IF NOT EXISTS `mg_genesis` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `mg_genesis`;

-- Data exporting was unselected.
-- Dumping structure for πίνακας mg_genesis.sysusrd
CREATE TABLE IF NOT EXISTS `sysusrd` (
  `SYSUSRD_ID` int(11) NOT NULL AUTO_INCREMENT,
  `SYSUSRD_SYSUSR_ID` int(11) DEFAULT NULL,
  `SYSUSRD_SYSHOST_CODE` varchar(50) DEFAULT NULL,
  `SYSUSRD_INSDATE` date NOT NULL,
  PRIMARY KEY (`SYSUSRD_ID`),
  KEY `SYSUSRD_SYSUSR_FK` (`SYSUSRD_SYSUSR_ID`),
  KEY `SYSUSRD_SYSHOST_FK` (`SYSUSRD_SYSHOST_CODE`),
  CONSTRAINT `SYSUSRD_SYSHOST_FK` FOREIGN KEY (`SYSUSRD_SYSHOST_CODE`) REFERENCES `syshost` (`SYSHOST_CODE`),
  CONSTRAINT `SYSUSRD_SYSUSR_FK` FOREIGN KEY (`SYSUSRD_SYSUSR_ID`) REFERENCES `sysusr` (`SYSUSR_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Data exporting was unselected.
-- Dumping structure for trigger mg_genesis.syshost_BEFORE_INSERT
SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE='';

 if NEW.syshost_code is null then
  SET next_id = (SELECT AUTO_INCREMENT 
                          FROM information_schema.TABLES 
                          WHERE TABLE_SCHEMA=DATABASE() AND 
                                TABLE_NAME='syshost');
                                
  SET NEW.syshost_code = LPAD(next_id, 4,'0');
 end if;
end//
DELIMITER ;

-- Dumping structure for trigger mg_genesis.syslog_before_insert
SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
END//
DELIMITER ;

