0

I have tried to search for an answer but my results have not been fruitful. Any suggestions would be greatly appreciated.

The error is:

ERROR 1064 (42000): 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 'Order' at line 1

And the script I'm running is:

-- MySQL Script generated by MySQL Workbench
-- Thu 12 Oct 2017 01:11:28 PM EDT
-- Model: New Model    Version: 1.0    
-- 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='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
-- -----------------------------------------------------
-- Schema customer
-- -----------------------------------------------------
-- This schema was created for a stub table

-- -----------------------------------------------------
-- Schema customer
--
-- This schema was created for a stub table
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `customer` ;
USE `mydb` ;

-- -----------------------------------------------------
-- Table `mydb`.`Product`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Product` (
  `product_id` INT NOT NULL AUTO_INCREMENT,
  `Product_name` VARCHAR(45) NULL,
  `color` VARCHAR(45) NULL,
  `cost` VARCHAR(45) NULL,
  `price` INT NULL,
  `catagory` VARCHAR(45) NULL,
  `description` VARCHAR(45) NULL,
  `stock` VARCHAR(3) NULL,
  PRIMARY KEY (`product_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`customer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`customer` (
  `name` VARCHAR(45) NULL,
  `address` VARCHAR(45) NULL,
  `city` VARCHAR(45) NULL,
  `country` VARCHAR(45) NULL,
  `customer_id` VARCHAR(45) NOT NULL,
  `state` VARCHAR(2) NULL,
  `zip` INT NULL,
  `credit_card` BIGINT(17) NULL,
  PRIMARY KEY (`customer_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Order`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Order` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `price` INT NULL,
  `date` DATE NULL,
  `shipping_date` DATE NULL,
  `completed` VARCHAR(3) NULL,
  `urgent_order` VARCHAR(3) NULL,
  `vip` VARCHAR(3) NULL,
  `quantity` INT NULL,
  `product_id` INT NULL,
  `repeat_order` VARCHAR(3) NULL,
  `customer_customer_id` VARCHAR(45) NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_Order_customer1_idx` (`customer_customer_id` ASC),
  CONSTRAINT `fk_Order_customer1`
    FOREIGN KEY (`customer_customer_id`)
    REFERENCES `mydb`.`customer` (`customer_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`review`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`review` (
  `review_id` INT NOT NULL AUTO_INCREMENT,
  `rating` INT NULL,
  `review` VARCHAR(45) NULL,
  `order_id` INT NULL,
  `date` DATE NULL,
  `Product_product_id` INT NULL,
  PRIMARY KEY (`review_id`),
  INDEX `fk_review_Product1_idx` (`Product_product_id` ASC),
  CONSTRAINT `fk_review_Product1`
    FOREIGN KEY (`Product_product_id`)
    REFERENCES `mydb`.`Product` (`product_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Order_has_Product`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Order_has_Product` (
  `Order_id` INT NULL,
  `Product_product_id` INT NULL,
  PRIMARY KEY (`Order_id`, `Product_product_id`),
  INDEX `fk_Order_has_Product_Product1_idx` (`Product_product_id` ASC),
  INDEX `fk_Order_has_Product_Order1_idx` (`Order_id` ASC),
  CONSTRAINT `fk_Order_has_Product_Order1`
    FOREIGN KEY (`Order_id`)
    REFERENCES `mydb`.`Order` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_Order_has_Product_Product1`
    FOREIGN KEY (`Product_product_id`)
    REFERENCES `mydb`.`Product` (`product_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;

USE `customer` ;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  • 1
    Have you tried manually executing it one step at a time to determine which step breaks? – indiri Oct 12 '17 at 19:10
  • I tried running just the table creation commands on db-fiddle.com, and got an error because the FK id fields in Order_has_Product are listed as NULLable, but are also the parts of a composite foreign key. Can't say that's the problem you're hitting, but it's worth mentioning. – RDFozz Oct 12 '17 at 19:39
  • I changed the keys to unique and no luck – SilverSurfer Oct 13 '17 at 19:46
1

Are you sure you still have an error with the following script ?

change :

CREATE TABLE IF NOT EXISTS `mydb`.`Order_has_Product` (
  `Order_id` INT{+ NOT+} NULL,
  `Product_product_id` INT{+ NOT+} NULL,

(it work on my MySQL 5.7, I don't have any mariadb to try now)

-- MySQL Script generated by MySQL Workbench
-- Thu 12 Oct 2017 01:11:28 PM EDT
-- Model: New Model    Version: 1.0    
-- 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='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
-- -----------------------------------------------------
-- Schema customer
-- -----------------------------------------------------
-- This schema was created for a stub table

-- -----------------------------------------------------
-- Schema customer
--
-- This schema was created for a stub table
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `customer` ;
USE `mydb` ;

-- -----------------------------------------------------
-- Table `mydb`.`Product`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Product` (
  `product_id` INT NOT NULL AUTO_INCREMENT,
  `Product_name` VARCHAR(45) NULL,
  `color` VARCHAR(45) NULL,
  `cost` VARCHAR(45) NULL,
  `price` INT NULL,
  `catagory` VARCHAR(45) NULL,
  `description` VARCHAR(45) NULL,
  `stock` VARCHAR(3) NULL,
  PRIMARY KEY (`product_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`customer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`customer` (
  `name` VARCHAR(45) NULL,
  `address` VARCHAR(45) NULL,
  `city` VARCHAR(45) NULL,
  `country` VARCHAR(45) NULL,
  `customer_id` VARCHAR(45) NOT NULL,
  `state` VARCHAR(2) NULL,
  `zip` INT NULL,
  `credit_card` BIGINT(17) NULL,
  PRIMARY KEY (`customer_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Order`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Order` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `price` INT NULL,
  `date` DATE NULL,
  `shipping_date` DATE NULL,
  `completed` VARCHAR(3) NULL,
  `urgent_order` VARCHAR(3) NULL,
  `vip` VARCHAR(3) NULL,
  `quantity` INT NULL,
  `product_id` INT NULL,
  `repeat_order` VARCHAR(3) NULL,
  `customer_customer_id` VARCHAR(45) NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_Order_customer1_idx` (`customer_customer_id` ASC),
  CONSTRAINT `fk_Order_customer1`
    FOREIGN KEY (`customer_customer_id`)
    REFERENCES `mydb`.`customer` (`customer_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`review`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`review` (
  `review_id` INT NOT NULL AUTO_INCREMENT,
  `rating` INT NULL,
  `review` VARCHAR(45) NULL,
  `order_id` INT NULL,
  `date` DATE NULL,
  `Product_product_id` INT NULL,
  PRIMARY KEY (`review_id`),
  INDEX `fk_review_Product1_idx` (`Product_product_id` ASC),
  CONSTRAINT `fk_review_Product1`
    FOREIGN KEY (`Product_product_id`)
    REFERENCES `mydb`.`Product` (`product_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Order_has_Product`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Order_has_Product` (
  `Order_id` INT NOT NULL,
  `Product_product_id` INT NOT NULL,
  PRIMARY KEY (`Order_id`, `Product_product_id`),
  INDEX `fk_Order_has_Product_Product1_idx` (`Product_product_id` ASC),
  INDEX `fk_Order_has_Product_Order1_idx` (`Order_id` ASC),
  CONSTRAINT `fk_Order_has_Product_Order1`
    FOREIGN KEY (`Order_id`)
    REFERENCES `mydb`.`Order` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_Order_has_Product_Product1`
    FOREIGN KEY (`Product_product_id`)
    REFERENCES `mydb`.`Product` (`product_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;

USE `customer` ;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  • I've verified that this works on MariaDB 10.2. I guess what is different here is that Order_has_Product.Product_product_id INT is defined as NOT NULL. – dbdemon Apr 20 '18 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.