CREATE TABLE `log_type` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `nazov` varchar(255) DEFAULT NULL,
  `code` varchar(45) DEFAULT NULL,
  `primary_table` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE  TABLE IF NOT EXISTS `logovanie` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `log_type_id` INT UNSIGNED NOT NULL ,
  `user_id` INT NULL ,
  `user_table` VARCHAR(45) NULL ,
  `datum` DATETIME NULL ,
  `primary_id` INT NULL ,
  `primary_table` VARCHAR(45) NULL ,
  `ip` VARCHAR(45) NULL ,
  `zmeny` TEXT NULL ,
  `poznamka` TEXT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `logovanie_FKIndex1` (`log_type_id` ASC) ,
  INDEX `logovanie_FKIndex2` (`user_id` ASC) ,
  INDEX `logovanie_FKIndex3` (`primary_id` ASC) ,
  CONSTRAINT `fk_logovanie_log_type`
  FOREIGN KEY (`log_type_id` )
  REFERENCES `log_type` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
  ENGINE = InnoDB DEFAULT CHARACTER SET = utf8;