Error creating table with INDEX VISIBLE in Workbench

Asked

Viewed 3,395 times

6

I created a diagram of a BD using Mysql Workbench and had it generated. But the following error happens when I run the query:

Executing SQL script in server
ERROR: Error 1064: 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 '
  INDEX `fk_carro_leilao1_idx` (`leilao_idleilao` ASC) VISIBLE,
  CONSTRAINT `f' at line 15

SQL code:

    -- -----------------------------------------------------
    -- Table `carrosleilao`.`carro`
    -- -----------------------------------------------------
    CREATE TABLE IF NOT EXISTS `carrosleilao`.`carro` (
      `idcarro` INT NOT NULL AUTO_INCREMENT,
      `modelo` VARCHAR(45) NOT NULL,
      `marca` VARCHAR(45) NOT NULL,
      `ano` VARCHAR(5) NOT NULL,
      `combustivel` VARCHAR(45) NOT NULL,
      `precoFIPE` VARCHAR(45) NOT NULL,
      `referencia` VARCHAR(45) NOT NULL,
      `preco_idpreco` INT NOT NULL,
      `leilao_idleilao` INT NOT NULL,
      PRIMARY KEY (`idcarro`, `preco_idpreco`, `leilao_idleilao`),
      INDEX `fk_carro_preco_idx` (`preco_idpreco` ASC) VISIBLE,
      INDEX `fk_carro_leilao1_idx` (`leilao_idleilao` ASC) VISIBLE,
      CONSTRAINT `fk_carro_preco`
        FOREIGN KEY (`preco_idpreco`)
        REFERENCES `carrosleilao`.`preco` (`idpreco`)
        ON DELETE NO ACTION
        ON UPDATE NO ACTION,
      CONSTRAINT `fk_carro_leilao1`
        FOREIGN KEY (`leilao_idleilao`)
        REFERENCES `carrosleilao`.`leilao` (`idleilao`)
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB

I could not identify the problem because the script was generated by the tool itself.

1 answer

10


Observing the "next syntax error" part, I risk saying that you are using Mysql version before 8.0. Perhaps version 5.7 which is the most common.

See available index options according to documentation:

index_option:
    KEY_BLOCK_SIZE [=] value
  | index_type
  | WITH PARSER parser_name
  | COMMENT 'string'

Does that mean that you do not have the index visibility option:

  INDEX `fk_carro_preco_idx` (`preco_idpreco` ASC) VISIBLE,
  INDEX `fk_carro_leilao1_idx` (`leilao_idleilao` ASC) VISIBLE,

Simply remove the option VISIBLE of the consultation that will continue.

Recommended reading: Mysql 8.0 Reference Manual - 8.3.12 Invisible Indexes


BONUS:

"- the script was generated by the tool itself"

It turns out that Workbench, by default, comes configured for modeling in Mysql version 8.0.

To change, access the preferences related to Mysql modeling:

Edit > Preferences > Modeling > Mysql.

Change the option Default Target Mysql Version for 5.7 (or your Mysql server version).

Browser other questions tagged

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