BD creation with Mysql - Mariadb - Workbench

Asked

Viewed 156 times

1

I’m trying to create a BD as Diagram done in Workbench but returns the error below:

ERROR 1064 (42000) at line 45: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '
CONSTRAINT `fk_funcionario_cargo`
FOREIGN KEY (`cargo_idcargo`)
REFER' at line 8
Operation failed with exitcode 1

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='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

CREATE SCHEMA IF NOT EXISTS `trabalhoa12` ;
USE `trabalhoa12` ;

CREATE TABLE IF NOT EXISTS `trabalhoa12`.`projeto` (
  `idprojeto` INT NOT NULL,
  `descproj` VARCHAR(45) NULL,
  `orcamento` DECIMAL(10,2) NULL,
  PRIMARY KEY (`idprojeto`))
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `trabalhoa12`.`cargo` (
  `idcargo` INT NOT NULL,
  `cargo` VARCHAR(20) NULL,
  `salario` DECIMAL(8,2) NULL COMMENT ' ',
  PRIMARY KEY (`idcargo`))
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `trabalhoa12`.`funcionario` (
  `idfuncionario` INT NOT NULL,
  `cargo_idcargo` INT NOT NULL,
  `nome` VARCHAR(45) NULL,
  `uf` CHAR(2) NULL,
  `cidade` VARCHAR(20) NULL,
  PRIMARY KEY (`idfuncionario`, `cargo_idcargo`),
  INDEX `fk_funcionario_cargo_idx` (`cargo_idcargo` ASC) VISIBLE,
  CONSTRAINT `fk_funcionario_cargo`
    FOREIGN KEY (`cargo_idcargo`)
    REFERENCES `trabalhoa12`.`cargo` (`idcargo`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = ndbcluster;


CREATE TABLE IF NOT EXISTS `trabalhoa12`.`projeunc` (
  `projeto_idprojeto` INT NOT NULL,
  `funcionario_idfuncionario` INT NOT NULL,
  `reponsabilidade` VARCHAR(45) NULL,
  `tempolotacao` DECIMAL(2) NULL,
  PRIMARY KEY (`projeto_idprojeto`, `funcionario_idfuncionario`),
  INDEX `fk_projeunc_funcionario1_idx` (`funcionario_idfuncionario` ASC) VISIBLE,
  CONSTRAINT `fk_projeunc_projeto1`
    FOREIGN KEY (`projeto_idprojeto`)
    REFERENCES `trabalhoa12`.`projeto` (`idprojeto`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_projeunc_funcionario1`
    FOREIGN KEY (`funcionario_idfuncionario`)
    REFERENCES `trabalhoa12`.`funcionario` (`idfuncionario`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  • Out of curiosity, the database is Mariadb?

1 answer

1


In creating the indices fk_funcionario_cargo_idx and fk_projeunc_funcionario1_idx remove the option VISIBLE. By definition Mysql indexes are visible. If you want to change the visibility of an index use the command ALTER TABLE if you want to create an invisible index do it with CREATE INDEX.

CREATE TABLE IF NOT EXISTS `trabalhoa12`.`funcionario` (
  `idfuncionario` INT NOT NULL,
  `cargo_idcargo` INT NOT NULL,
  `nome` VARCHAR(45) NULL,
  `uf` CHAR(2) NULL,
  `cidade` VARCHAR(20) NULL,
  PRIMARY KEY (`idfuncionario`, `cargo_idcargo`),

  INDEX `fk_funcionario_cargo_idx` (`cargo_idcargo` ASC),


  CONSTRAINT `fk_funcionario_cargo`
    FOREIGN KEY (`cargo_idcargo`)
    REFERENCES `trabalhoa12`.`cargo` (`idcargo`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = ndbcluster;


CREATE TABLE IF NOT EXISTS `trabalhoa12`.`projeunc` (
  `projeto_idprojeto` INT NOT NULL,
  `funcionario_idfuncionario` INT NOT NULL,
  `reponsabilidade` VARCHAR(45) NULL,
  `tempolotacao` DECIMAL(2) NULL,
  PRIMARY KEY (`projeto_idprojeto`, `funcionario_idfuncionario`),

  INDEX `fk_projeunc_funcionario1_idx` (`funcionario_idfuncionario` ASC),

  CONSTRAINT `fk_projeunc_projeto1`
    FOREIGN KEY (`projeto_idprojeto`)
    REFERENCES `trabalhoa12`.`projeto` (`idprojeto`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_projeunc_funcionario1`
    FOREIGN KEY (`funcionario_idfuncionario`)
    REFERENCES `trabalhoa12`.`funcionario` (`idfuncionario`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.