我正在使用 EER 模型中的 MySQL Wordbench 对我的数据库进行建模,即:
因此,在对我的数据库进行建模后,我导出到一个 SQL 脚本并尝试运行它,但它只创建了三个表:
为什么会这样?它不应该创建所有表吗?
这是我导出时生成的脚本:
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
CREATE SCHEMA IF NOT EXISTS `brainset` DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci ;
USE `brainset` ;
-- -----------------------------------------------------
-- Table `brainset`.`departamento`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`departamento` (
`ID` TINYINT UNSIGNED NOT NULL ,
`departamento` VARCHAR(50) NOT NULL ,
PRIMARY KEY (`ID`) ,
UNIQUE INDEX `departamento_UNIQUE` (`departamento` ASC) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `brainset`.`documento_escopo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`documento_escopo` (
`ID` TINYINT UNSIGNED NOT NULL ,
`escopo` CHAR(7) NOT NULL ,
PRIMARY KEY (`ID`) ,
UNIQUE INDEX `escopo_UNIQUE` (`escopo` ASC) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `brainset`.`procedimento_tipo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`procedimento_tipo` (
`ID` TINYINT UNSIGNED NOT NULL ,
`tipo` VARCHAR(50) NOT NULL ,
PRIMARY KEY (`ID`) ,
UNIQUE INDEX `tipo_UNIQUE` (`tipo` ASC) )
ENGINE = InnoDB
COMMENT = ' ';
-- -----------------------------------------------------
-- Table `brainset`.`procedimento`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`procedimento` (
`ID` SMALLINT UNSIGNED NOT NULL ,
`nome` VARCHAR(100) NOT NULL ,
`descricao` VARCHAR(1024) NOT NULL ,
`id_tipo` TINYINT UNSIGNED NOT NULL ,
`id_departamento` TINYINT UNSIGNED NOT NULL ,
`id_documento_complementar` INT UNSIGNED NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `fk_procedimento-procedimento_tipo` (`id_tipo` ASC, `id_departamento` ASC) ,
INDEX `fk_procedimento-departamento` (`id_departamento` ASC) ,
CONSTRAINT `fk_procedimento-procedimento_tipo`
FOREIGN KEY (`id_tipo` , `id_departamento` )
REFERENCES `brainset`.`procedimento_tipo` (`ID` , `ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_procedimento-departamento`
FOREIGN KEY (`id_departamento` )
REFERENCES `brainset`.`departamento` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `brainset`.`usuario`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`usuario` (
`ID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`nome` VARCHAR(100) NOT NULL ,
`foto` VARCHAR(200) NULL ,
`email` VARCHAR(45) NOT NULL ,
`senha` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `brainset`.`documento`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`documento` (
`ID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`id_procedimento` SMALLINT UNSIGNED NOT NULL ,
`data` DATETIME NOT NULL ,
`revisao` TINYINT NOT NULL ,
`id_escopo` TINYINT UNSIGNED NOT NULL ,
`id_documento_complementar` INT UNSIGNED NULL ,
`id_usuario` INT UNSIGNED NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `fk_documento-documento_escopo` (`id_escopo` ASC) ,
INDEX `fk_documento-procedimento` (`id_procedimento` ASC) ,
INDEX `fk_documento-documento` (`id_documento_complementar` ASC) ,
INDEX `fk_documento-usuario` (`id_usuario` ASC) ,
CONSTRAINT `fk_documento-documento_escopo`
FOREIGN KEY (`id_escopo` )
REFERENCES `brainset`.`documento_escopo` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_documento-procedimento`
FOREIGN KEY (`id_procedimento` )
REFERENCES `brainset`.`procedimento` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_documento-documento`
FOREIGN KEY (`id_documento_complementar` )
REFERENCES `brainset`.`documento` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_documento-usuario`
FOREIGN KEY (`id_usuario` )
REFERENCES `brainset`.`usuario` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `brainset`.`questao`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`questao` (
`ID` INT UNSIGNED NOT NULL ,
`questao` VARCHAR(1024) NOT NULL ,
`descricao` VARCHAR(1024) NULL ,
`observacao` VARCHAR(1024) NULL ,
`data` DATETIME NOT NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `brainset`.`questao_tipo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`questao_tipo` (
`ID` TINYINT UNSIGNED NOT NULL ,
`nome` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `brainset`.`questao_campo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`questao_campo` (
`ID` INT UNSIGNED NOT NULL ,
`id_questao` INT NOT NULL ,
`id_questao_tipo` TINYINT NOT NULL ,
`descricao` VARCHAR(1024) NULL ,
PRIMARY KEY (`ID`) ,
INDEX `fk_questao_campo-questao` (`id_questao` ASC) ,
INDEX `fk_questao_campo-questao-tipo` (`id_questao_tipo` ASC) ,
CONSTRAINT `fk_questao_campo-questao`
FOREIGN KEY (`id_questao` )
REFERENCES `brainset`.`questao` (`ID` )
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_questao_campo-questao-tipo`
FOREIGN KEY (`id_questao_tipo` )
REFERENCES `brainset`.`questao_tipo` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `brainset`.`questao_escolha`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`questao_escolha` (
`ID` INT UNSIGNED NOT NULL ,
`id_questao_campo` INT NOT NULL ,
`nome` VARCHAR(64) NOT NULL ,
`valor` VARCHAR(64) NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `fk_questao_escolha-questao_campo` (`id_questao_campo` ASC) ,
CONSTRAINT `fk_questao_escolha-questao_campo`
FOREIGN KEY (`id_questao_campo` )
REFERENCES `brainset`.`questao_campo` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `brainset`.`questao_resposta`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`questao_resposta` (
`ID` INT UNSIGNED NOT NULL ,
`id_questao` INT NOT NULL ,
`resposta` VARCHAR(1024) NOT NULL ,
`data` DATETIME NOT NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `brainset`.`questao_consulta`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`questao_consulta` (
`ID` INT UNSIGNED NOT NULL ,
`id_usuario` INT NOT NULL ,
`id_questao` INT NOT NULL ,
`id_questao_resposta` INT NOT NULL ,
`data` TIMESTAMP NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `fk_questao_consulta-usuario` (`id_usuario` ASC) ,
INDEX `fk_questao_consulta-questao` (`id_questao` ASC) ,
INDEX `fk_questao_consulta-questao_resposta` (`id_questao_resposta` ASC) ,
CONSTRAINT `fk_questao_consulta-usuario`
FOREIGN KEY (`id_usuario` )
REFERENCES `brainset`.`usuario` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_questao_consulta-questao`
FOREIGN KEY (`id_questao` )
REFERENCES `brainset`.`questao` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_questao_consulta-questao_resposta`
FOREIGN KEY (`id_questao_resposta` )
REFERENCES `brainset`.`questao_resposta` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = ' ';
-- -----------------------------------------------------
-- Table `brainset`.`departamento_equipe`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `brainset`.`departamento_equipe` (
`ID` INT UNSIGNED NOT NULL ,
`id_departamento` TINYINT UNSIGNED NOT NULL ,
`id_usuario` INT UNSIGNED NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `fk_departamento_equipe-departamento` (`id_departamento` ASC) ,
INDEX `fk_departamento_equipe-usuario` (`id_usuario` ASC) ,
CONSTRAINT `fk_departamento_equipe-departamento`
FOREIGN KEY (`id_departamento` )
REFERENCES `brainset`.`departamento` (`ID` )
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_departamento_equipe-usuario`
FOREIGN KEY (`id_usuario` )
REFERENCES `brainset`.`usuario` (`ID` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
谢谢。