我正在使用MySQL Workbench。 在该行:
REFERENCES `mydb`.`Registre` (`idDoc` , `dateDoc` , `idFRP` , `idAudience`)
我收到错误
"Syntax error: missing 'closing parenthesis'".
My field in table Registre indexed
INDEX `INDEX` (`idMV` ASC, `idAudience` ASC, `idDoc` ASC, `idFRP` ASC, `INN` ASC, `dateDoc` ASC))
如果有任何帮助,我们将不胜感激。
这是SQL:`
-- MySQL Script generated by MySQL Workbench
-- 04/17/15 10:31:31
-- 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 COLLATE utf8_general_ci ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`MaterialValueList`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`MaterialValueList` ;
CREATE TABLE IF NOT EXISTS `mydb`.`MaterialValueList` (
`id` INT NOT NULL,
`materialValue` VARCHAR(45) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Audience`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Audience` ;
CREATE TABLE IF NOT EXISTS `mydb`.`Audience` (
`id` INT NOT NULL,
`auditorium` VARCHAR(45) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`FRP`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`FRP` ;
CREATE TABLE IF NOT EXISTS `mydb`.`FRP` (
`id` INT NOT NULL,
`firstName` VARCHAR(45) NULL,
`lastName` VARCHAR(45) NULL,
`contactInfo` VARCHAR(45) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Registre`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Registre` ;
CREATE TABLE IF NOT EXISTS `mydb`.`Registre` (
`id` INT NOT NULL,
`idMV` INT NOT NULL,
`idAudience` INT NOT NULL,
`idDoc` INT NOT NULL,
`idFRP` INT NOT NULL,
`INN` INT NOT NULL,
`count` INT NOT NULL,
`dateDoc` DATE NOT NULL,
PRIMARY KEY (`id`),
INDEX `INDEX` (`idMV` ASC, `idAudience` ASC, `idDoc` ASC, `idFRP` ASC, `INN` ASC, `dateDoc` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`PurchaseInvoice`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`PurchaseInvoice` ;
CREATE TABLE IF NOT EXISTS `mydb`.`PurchaseInvoice` (
`id` INT NOT NULL,
`dateDoc` DATE NOT NULL,
`idFRP` INT NULL,
`idAudience` INT NULL,
PRIMARY KEY (`id`),
INDEX `InvoiceFRPFK_idx` (`idFRP` ASC),
INDEX `fk_PurchaseInvoice_Audience1_idx` (`idAudience` ASC),
INDEX `fk_PurchaseInvoice_Registre1_idx` (`id` ASC, `dateDoc` ASC, `idFRP` ASC, `idAudience` ASC),
CONSTRAINT `InvoiceFRPFK`
FOREIGN KEY (`idFRP`)
REFERENCES `mydb`.`FRP` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_PurchaseInvoice_Audience1`
FOREIGN KEY (`idAudience`)
REFERENCES `mydb`.`Audience` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_PurchaseInvoice_Registre1`
FOREIGN KEY (`id` , `dateDoc` , `idFRP` , `idAudience`)
REFERENCES `mydb`.`Registre` (`idDoc` , `dateDoc` , `idFRP` , `idAudience`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`PurchaseInvoiceList`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`PurchaseInvoiceList` ;
CREATE TABLE IF NOT EXISTS `mydb`.`PurchaseInvoiceList` (
`id` INT NOT NULL,
`idMV` INT NOT NULL,
`inventoryNumber` INT NOT NULL,
`count` INT NULL,
`PurchaseInvoiceID` INT NOT NULL,
INDEX `InvoiceMaterialFK_idx` (`idMV` ASC),
PRIMARY KEY (`id`),
UNIQUE INDEX `id_UNIQUE` (`id` ASC),
INDEX `fk_PurchaseInvoiceList_Registre1_idx` (`idMV` ASC, `inventoryNumber` ASC),
INDEX `fk_PurchaseInvoiceList_PurchaseInvoice1_idx` (`PurchaseInvoiceID` ASC),
CONSTRAINT `InvoiceListMaterialFK`
FOREIGN KEY (`idMV`)
REFERENCES `mydb`.`MaterialValueList` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_PurchaseInvoiceList_Registre1`
FOREIGN KEY (`idMV` , `inventoryNumber`)
REFERENCES `mydb`.`Registre` (`idMV` , `INN`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_PurchaseInvoiceList_PurchaseInvoice1`
FOREIGN KEY (`PurchaseInvoiceID`)
REFERENCES `mydb`.`PurchaseInvoice` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`WriteOff`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`WriteOff` ;
CREATE TABLE IF NOT EXISTS `mydb`.`WriteOff` (
`id` INT NOT NULL,
`dateDoc` DATE NOT NULL,
`idAudience` INT NULL,
`idFRP` INT NULL,
PRIMARY KEY (`id`),
INDEX `WriteOffAudience_idx` (`idAudience` ASC),
INDEX `WriteOffFRPFK_idx` (`idFRP` ASC),
INDEX `fk_WriteOff_Registre1_idx` (`id` ASC, `dateDoc` ASC, `idFRP` ASC, `idAudience` ASC),
CONSTRAINT `WriteOffAudienceFK`
FOREIGN KEY (`idAudience`)
REFERENCES `mydb`.`Audience` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `WriteOffFRPFK`
FOREIGN KEY (`idFRP`)
REFERENCES `mydb`.`FRP` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_WriteOff_Registre1`
FOREIGN KEY (`id` , `dateDoc` , `idFRP` , `idAudience`)
REFERENCES `mydb`.`Registre` (`idDoc` , `dateDoc` , `idFRP` , `idAudience`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`WriteOffList`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`WriteOffList` ;
CREATE TABLE IF NOT EXISTS `mydb`.`WriteOffList` (
`id` INT NOT NULL,
`idMV` INT NOT NULL,
`inventoryNumber` INT NOT NULL,
`count` INT NULL,
`WriteOffID` INT NOT NULL,
INDEX `WriteOffListMaterialFK_idx` (`idMV` ASC),
PRIMARY KEY (`id`),
UNIQUE INDEX `id_UNIQUE` (`id` ASC),
INDEX `fk_WriteOffList_Registre1_idx` (`idMV` ASC, `inventoryNumber` ASC),
INDEX `fk_WriteOffList_WriteOff1_idx` (`WriteOffID` ASC),
CONSTRAINT `WriteOffListMaterialFK`
FOREIGN KEY (`idMV`)
REFERENCES `mydb`.`MaterialValueList` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_WriteOffList_Registre1`
FOREIGN KEY (`idMV` , `inventoryNumber`)
REFERENCES `mydb`.`Registre` (`idMV` , `INN`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_WriteOffList_WriteOff1`
FOREIGN KEY (`WriteOffID`)
REFERENCES `mydb`.`WriteOff` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`MovingMV`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`MovingMV` ;
CREATE TABLE IF NOT EXISTS `mydb`.`MovingMV` (
`id` INT NOT NULL,
`dateDoc` DATE NOT NULL,
`idFRPto` INT NOT NULL,
`idAudienceto` INT NOT NULL,
`idFRPfrom` INT NULL,
`idAudiencefrom` INT NULL,
INDEX `MovingMVFEPFK_idx` (`idFRPto` ASC, `idFRPfrom` ASC),
INDEX `MovingMVAudienceFK_idx` (`idAudienceto` ASC, `idAudiencefrom` ASC),
INDEX `fk_MovingMV_Registre1_idx` (`id` ASC, `dateDoc` ASC, `idFRPto` ASC, `idAudienceto` ASC),
PRIMARY KEY (`id`),
CONSTRAINT `MovingMVFEPFK`
FOREIGN KEY (`idFRPto` , `idFRPfrom`)
REFERENCES `mydb`.`FRP` (`id` , `id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `MovingMVAudienceFK`
FOREIGN KEY (`idAudienceto` , `idAudiencefrom`)
REFERENCES `mydb`.`Audience` (`id` , `id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_MovingMV_Registre1`
FOREIGN KEY (`id` , `dateDoc` , `idFRPto` , `idAudienceto`)
REFERENCES `mydb`.`Registre` (`idDoc` , `dateDoc` , `idFRP` , `idAudience`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`MovingMVList`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`MovingMVList` ;
CREATE TABLE IF NOT EXISTS `mydb`.`MovingMVList` (
`id` INT NOT NULL,
`idMV` INT NOT NULL,
`inventoryNumber` INT NOT NULL,
`count` INT NULL,
`MovingID` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_MovingMVList_MaterialValueList1_idx` (`idMV` ASC),
UNIQUE INDEX `id_UNIQUE` (`id` ASC),
INDEX `fk_MovingMVList_Registre1_idx` (`idMV` ASC, `inventoryNumber` ASC),
INDEX `fk_MovingMVList_MovingMV1_idx` (`MovingID` ASC),
CONSTRAINT `fk_MovingMVList_MaterialValueList1`
FOREIGN KEY (`idMV`)
REFERENCES `mydb`.`MaterialValueList` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_MovingMVList_Registre1`
FOREIGN KEY (`idMV` , `inventoryNumber`)
REFERENCES `mydb`.`Registre` (`idMV` , `INN`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_MovingMVList_MovingMV1`
FOREIGN KEY (`MovingID`)
REFERENCES `mydb`.`MovingMV` (`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;
`
答案 0 :(得分:0)
您使用关键字索引两次。请删除一个:INDEX
INDEX`
CREATE TABLE IF NOT EXISTS `mydb`.`Registre` (
`id` INT NOT NULL,
`idMV` INT NOT NULL,
`idAudience` INT NOT NULL,
`idDoc` INT NOT NULL,
`idFRP` INT NOT NULL,
`INN` INT NOT NULL,
`count` INT NOT NULL,
`dateDoc` DATE NOT NULL,
PRIMARY KEY (`id`),
INDEX (`idMV` ASC, `idAudience` ASC, `idDoc` ASC, `idFRP` ASC, `INN` ASC, `dateDoc` ASC))
ENGINE = InnoDB;