mariadb为什么会给出使用工作台创建的sql文件的语法错误

问题描述 投票:-1回答:1

我已经用mysql工作台创建了一个模型,并且每次我要执行sql文件时都给出了此错误

ERROR 1064(42000)在文件55行:'D:\ db.sql':SQL语法有错误;查看与您的MariaDB服务器版本相对应的手册,以获取在'附近使用的正确语法约束fk_customer_order_customer1外键(customer_id)'在第8行

错误1064(42000),在文件中的第76行:'D:\ db.sql':您的SQL语法有错误;查看与您的MariaDB服务器版本相对应的手册,以获取在'附近使用的正确语法约束fk_product_category外键(category_id)第9行的REFERENC'

错误1064(42000)在文件98行中:'D:\ db.sql':SQL语法有错误;查看与您的MariaDB服务器版本相对应的手册,以获取在'附近使用的正确语法索引fk_ordered_product_productcustomer_order_id ASC)可见,第6行的CONST'

这是为我生成的代码mysql workbench

  -- MySQL Workbench Forward Engineering

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';

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema ecommerce_ee
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `ecommerce_ee` ;

-- -----------------------------------------------------
-- Schema ecommerce_ee
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `ecommerce_ee` ;
USE `ecommerce_ee` ;

-- -----------------------------------------------------
-- Table `ecommerce_ee`.`customer`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `ecommerce_ee`.`customer` ;

CREATE TABLE IF NOT EXISTS `ecommerce_ee`.`customer` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(45) NOT NULL,
  `email` VARCHAR(45) NOT NULL,
  `phone` VARCHAR(45) NOT NULL,
  `address` VARCHAR(45) NOT NULL,
  `city_region` VARCHAR(45) NOT NULL,
  `cc_number` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `ecommerce_ee`.`category`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `ecommerce_ee`.`category` ;

CREATE TABLE IF NOT EXISTS `ecommerce_ee`.`category` (
  `id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `ecommerce_ee`.`customer_order`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `ecommerce_ee`.`customer_order` ;

CREATE TABLE IF NOT EXISTS `ecommerce_ee`.`customer_order` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `amount` DECIMAL(6,2) NOT NULL,
  `date_created` TIMESTAMP NOT NULL,
  `confirmation_number` INT UNSIGNED NOT NULL,
  `customer_id` INT UNSIGNED NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_customer_order_customer` (`customer_id` ASC) VISIBLE,
  CONSTRAINT `fk_customer_order_customer1`
    FOREIGN KEY (`customer_id`)
    REFERENCES `ecommerce_ee`.`customer` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `ecommerce_ee`.`product`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `ecommerce_ee`.`product` ;

CREATE TABLE IF NOT EXISTS `ecommerce_ee`.`product` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(45) NOT NULL,
  `price` DECIMAL(6,2) NOT NULL,
  `description` TINYTEXT NULL,
  `last_update` TIMESTAMP NOT NULL,
  `category_id` TINYINT UNSIGNED NOT NULL,
  PRIMARY KEY (`id`, `name`),
  INDEX `fk_product_category` (`category_id` ASC) VISIBLE,
  CONSTRAINT `fk_product_category`
    FOREIGN KEY (`category_id`)
    REFERENCES `ecommerce_ee`.`category` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `ecommerce_ee`.`ordered_product`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `ecommerce_ee`.`ordered_product` ;

CREATE TABLE IF NOT EXISTS `ecommerce_ee`.`ordered_product` (
  `customer_order_id` INT UNSIGNED NOT NULL,
  `product_id` INT UNSIGNED NOT NULL,
  `quantity` SMALLINT UNSIGNED NOT NULL,
  PRIMARY KEY (`customer_order_id`, `product_id`),
  INDEX `fk_ordered_product_customer_order` (`product_id` ASC, `quantity` ASC) VISIBLE,
  INDEX `fk_ordered_product_product` (`customer_order_id` ASC) VISIBLE,
  CONSTRAINT `fk_customer_order_has_product_customer_order1`
    FOREIGN KEY (`customer_order_id`)
    REFERENCES `ecommerce_ee`.`customer_order` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_customer_order_has_product_product1`
    FOREIGN KEY (`product_id` , `quantity`)
    REFERENCES `ecommerce_ee`.`product` (`id` , `name`)
    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;
sql mariadb
1个回答
0
投票

删除关键字VISIBLE。 (这只是before“附近”文本。)

© www.soinside.com 2019 - 2024. All rights reserved.