Я создал следующую модель EER, используя MySQL Workbench:
Затем я перешел к PHPMyAdmin, создал базу данных с тем же именем, что и у диаграммы (и с той же кодировкой / сопоставлением).
Когда я занимался форвард-инжинирингом, для создания БД я получил следующую ошибку:
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 '
CONSTRAINT `fk_transactions_transaction_types1`
FOREIGN KEY (`transaction' at line 9
SQL Code:
-- -----------------------------------------------------
-- Table `mydb`.`transactions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`transactions` (
`transactionID` INT(11) NOT NULL,
`transaction_types_transaction_typeID` INT(11) NOT NULL,
`date` DATETIME NOT NULL,
PRIMARY KEY (`transactionID`, `transaction_types_transaction_typeID`),
INDEX `fk_transactions_transaction_types1_idx` (`transaction_types_transaction_typeID` ASC) VISIBLE,
CONSTRAINT `fk_transactions_transaction_types1`
FOREIGN KEY (`transaction_types_transaction_typeID`)
REFERENCES `mydb`.`transaction_types` (`transaction_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 7 succeeded, 1 failed
Любое руководство приветствуется.
Я оставлю ниже полный код SQL, который используется в процессе.
Код SQL
CONSTRAINT `fk_transactions_transaction_types1`
FOREIGN KEY (`transaction' at line 9
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`book_prices`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`book_prices` (
`book_priceID` INT(11) NOT NULL,
`bookID` INT(11) NULL,
`price` DECIMAL(10,2) NULL,
`currency` CHAR(2) NULL,
`date_start` DATETIME NULL,
`date_end` DATETIME NULL,
PRIMARY KEY (`book_priceID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`transaction_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`transaction_types` (
`transaction_typeID` INT(11) NOT NULL,
`transactionID` INT(11) NULL,
PRIMARY KEY (`transaction_typeID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`transactions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`transactions` (
`transactionID` INT(11) NOT NULL,
`transaction_types_transaction_typeID` INT(11) NOT NULL,
`date` DATETIME NOT NULL,
PRIMARY KEY (`transactionID`, `transaction_types_transaction_typeID`),
INDEX `fk_transactions_transaction_types1_idx` (`transaction_types_transaction_typeID` ASC) VISIBLE,
CONSTRAINT `fk_transactions_transaction_types1`
FOREIGN KEY (`transaction_types_transaction_typeID`)
REFERENCES `mydb`.`transaction_types` (`transaction_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`books`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`books` (
`bookID` INT(11) GENERATED ALWAYS AS () VIRTUAL,
`name` VARCHAR(255) NULL,
`price` DECIMAL(10,2) NULL,
`book_prices_book_priceID` INT(11) NOT NULL,
`book_types_book_typeID` INT(11) NOT NULL,
`transactions_transactionID` INT(11) NOT NULL,
`transactions_transaction_types_transaction_typeID` INT(11) NOT NULL,
`ISBN` VARCHAR(13) NULL,
PRIMARY KEY (`bookID`, `book_prices_book_priceID`, `book_types_book_typeID`),
INDEX `fk_products_product_prices1_idx` (`book_prices_book_priceID` ASC) VISIBLE,
INDEX `fk_products_transactions1_idx` (`transactions_transactionID` ASC, `transactions_transaction_types_transaction_typeID` ASC) VISIBLE,
CONSTRAINT `fk_products_product_prices1`
FOREIGN KEY (`book_prices_book_priceID`)
REFERENCES `mydb`.`book_prices` (`book_priceID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_products_transactions1`
FOREIGN KEY (`transactions_transactionID` , `transactions_transaction_types_transaction_typeID`)
REFERENCES `mydb`.`transactions` (`transactionID` , `transaction_types_transaction_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`batch_transaction`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`batch_transaction` (
`transactionID` INT(11) NOT NULL,
`batchID` INT(11) NOT NULL,
`transactions_transactionID` INT(11) NOT NULL,
`transactions_transaction_types_transaction_typeID` INT(11) NOT NULL,
`date` DATETIME NULL,
PRIMARY KEY (`transactionID`, `transactions_transactionID`, `transactions_transaction_types_transaction_typeID`),
INDEX `fk_batch_transaction_transactions1_idx` (`transactions_transactionID` ASC, `transactions_transaction_types_transaction_typeID` ASC) VISIBLE,
CONSTRAINT `fk_batch_transaction_transactions1`
FOREIGN KEY (`transactions_transactionID` , `transactions_transaction_types_transaction_typeID`)
REFERENCES `mydb`.`transactions` (`transactionID` , `transaction_types_transaction_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`batches`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`batches` (
`batchID` INT(11) NOT NULL,
`batch_transaction_transactionID` INT(11) NULL,
`book_typeID` INT(11) NOT NULL,
`price` DECIMAL(10,2) NULL,
`supplierID` INT(11) NULL,
PRIMARY KEY (`batchID`),
INDEX `fk_batches_batch_transaction1_idx` (`batch_transaction_transactionID` ASC) VISIBLE,
CONSTRAINT `fk_batches_batch_transaction1`
FOREIGN KEY (`batch_transaction_transactionID`)
REFERENCES `mydb`.`batch_transaction` (`transactionID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`book_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`book_types` (
`book_typeID` INT(11) NOT NULL,
`name` VARCHAR(255) NULL,
`book_productID` INT(11) NOT NULL,
`books_book_prices_book_priceID` INT(11) NOT NULL,
`books_book_types_book_typeID` INT(11) NOT NULL,
`batches_batchID` INT(11) NOT NULL,
PRIMARY KEY (`book_typeID`, `book_productID`, `books_book_prices_book_priceID`, `books_book_types_book_typeID`),
INDEX `fk_product_types_products1_idx` (`book_productID` ASC, `books_book_prices_book_priceID` ASC, `books_book_types_book_typeID` ASC) VISIBLE,
INDEX `fk_product_types_batches1_idx` (`batches_batchID` ASC) VISIBLE,
CONSTRAINT `fk_product_types_products1`
FOREIGN KEY (`book_productID` , `books_book_prices_book_priceID` , `books_book_types_book_typeID`)
REFERENCES `mydb`.`books` (`bookID` , `book_prices_book_priceID` , `book_types_book_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_product_types_batches1`
FOREIGN KEY (`batches_batchID`)
REFERENCES `mydb`.`batches` (`batchID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`suppliers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`suppliers` (
`supplierID` INT(11) NOT NULL,
`batches_batchID` INT(11) NOT NULL,
`name` VARCHAR(255) NULL,
PRIMARY KEY (`supplierID`),
INDEX `fk_suppliers_batches1_idx` (`batches_batchID` ASC) VISIBLE,
CONSTRAINT `fk_suppliers_batches1`
FOREIGN KEY (`batches_batchID`)
REFERENCES `mydb`.`batches` (`batchID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`client_transaction`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`client_transaction` (
`transactionID` INT(11) NOT NULL,
`clientID` INT(11) NULL,
`transactions_transactionID` INT(11) NOT NULL,
`date` DATETIME NULL,
PRIMARY KEY (`transactionID`, `transactions_transactionID`),
INDEX `fk_client_transaction_transactions1_idx` (`transactions_transactionID` ASC) VISIBLE,
CONSTRAINT `fk_client_transaction_transactions1`
FOREIGN KEY (`transactions_transactionID`)
REFERENCES `mydb`.`transactions` (`transactionID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`clients`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`clients` (
`clientID` INT(11) NOT NULL,
`books_bookID` INT(11) NULL,
`books_book_prices_book_priceID` INT(11) NOT NULL,
`books_book_types_book_typeID` INT(11) NOT NULL,
`client_transaction_transactionID` INT(11) NOT NULL,
PRIMARY KEY (`clientID`),
INDEX `fk_clients_products1_idx` (`books_bookID` ASC, `books_book_prices_book_priceID` ASC, `books_book_types_book_typeID` ASC) VISIBLE,
INDEX `fk_clients_client_transaction1_idx` (`client_transaction_transactionID` ASC) VISIBLE,
CONSTRAINT `fk_clients_products1`
FOREIGN KEY (`books_bookID` , `books_book_prices_book_priceID` , `books_book_types_book_typeID`)
REFERENCES `mydb`.`books` (`bookID` , `book_prices_book_priceID` , `book_types_book_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_clients_client_transaction1`
FOREIGN KEY (`client_transaction_transactionID`)
REFERENCES `mydb`.`client_transaction` (`transactionID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`discounts`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`discounts` (
`discountID` INT(11) NOT NULL,
`Name` VARCHAR(255) NOT NULL,
`transactions_transactionID` INT(11) NULL,
`transactions_transaction_types_transaction_typeID` INT(11) NULL,
PRIMARY KEY (`discountID`),
INDEX `fk_discounts_transactions1_idx` (`transactions_transactionID` ASC, `transactions_transaction_types_transaction_typeID` ASC) VISIBLE,
CONSTRAINT `fk_discounts_transactions1`
FOREIGN KEY (`transactions_transactionID` , `transactions_transaction_types_transaction_typeID`)
REFERENCES `mydb`.`transactions` (`transactionID` , `transaction_types_transaction_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`discount_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`discount_types` (
`discount_typeID` INT(11) NOT NULL,
`Type` VARCHAR(255) NULL,
`discounts_discountID` INT(11) NOT NULL,
PRIMARY KEY (`discount_typeID`, `discounts_discountID`),
INDEX `fk_discount_types_discounts1_idx` (`discounts_discountID` ASC) VISIBLE,
CONSTRAINT `fk_discount_types_discounts1`
FOREIGN KEY (`discounts_discountID`)
REFERENCES `mydb`.`discounts` (`discountID`)
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;
РЕДАКТИРОВАТЬ: это не слово Visible, как я удалил его, и он по-прежнему выдает ошибку.
Скрипт без видимого:
-- 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 mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`book_prices`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`book_prices` (
`book_priceID` INT(11) NOT NULL,
`bookID` INT(11) NULL,
`price` DECIMAL(10,2) NULL,
`currency` CHAR(2) NULL,
`date_start` DATETIME NULL,
`date_end` DATETIME NULL,
PRIMARY KEY (`book_priceID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`transaction_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`transaction_types` (
`transaction_typeID` INT(11) NOT NULL,
`transactionID` INT(11) NULL,
PRIMARY KEY (`transaction_typeID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`transactions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`transactions` (
`transactionID` INT(11) NOT NULL,
`transaction_types_transaction_typeID` INT(11) NOT NULL,
`date` DATETIME NOT NULL,
PRIMARY KEY (`transactionID`, `transaction_types_transaction_typeID`),
INDEX `fk_transactions_transaction_types1_idx` (`transaction_types_transaction_typeID` ASC),
CONSTRAINT `fk_transactions_transaction_types1`
FOREIGN KEY (`transaction_types_transaction_typeID`)
REFERENCES `mydb`.`transaction_types` (`transaction_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`books`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`books` (
`bookID` INT(11) GENERATED ALWAYS AS () VIRTUAL,
`name` VARCHAR(255) NULL,
`price` DECIMAL(10,2) NULL,
`book_prices_book_priceID` INT(11) NOT NULL,
`book_types_book_typeID` INT(11) NOT NULL,
`transactions_transactionID` INT(11) NOT NULL,
`transactions_transaction_types_transaction_typeID` INT(11) NOT NULL,
`ISBN` VARCHAR(13) NULL,
PRIMARY KEY (`bookID`, `book_prices_book_priceID`, `book_types_book_typeID`),
INDEX `fk_products_product_prices1_idx` (`book_prices_book_priceID` ASC),
INDEX `fk_products_transactions1_idx` (`transactions_transactionID` ASC, `transactions_transaction_types_transaction_typeID` ASC) ,
CONSTRAINT `fk_products_product_prices1`
FOREIGN KEY (`book_prices_book_priceID`)
REFERENCES `mydb`.`book_prices` (`book_priceID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_products_transactions1`
FOREIGN KEY (`transactions_transactionID` , `transactions_transaction_types_transaction_typeID`)
REFERENCES `mydb`.`transactions` (`transactionID` , `transaction_types_transaction_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`batch_transaction`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`batch_transaction` (
`transactionID` INT(11) NOT NULL,
`batchID` INT(11) NOT NULL,
`transactions_transactionID` INT(11) NOT NULL,
`transactions_transaction_types_transaction_typeID` INT(11) NOT NULL,
`date` DATETIME NULL,
PRIMARY KEY (`transactionID`, `transactions_transactionID`, `transactions_transaction_types_transaction_typeID`),
INDEX `fk_batch_transaction_transactions1_idx` (`transactions_transactionID` ASC, `transactions_transaction_types_transaction_typeID` ASC),
CONSTRAINT `fk_batch_transaction_transactions1`
FOREIGN KEY (`transactions_transactionID` , `transactions_transaction_types_transaction_typeID`)
REFERENCES `mydb`.`transactions` (`transactionID` , `transaction_types_transaction_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`batches`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`batches` (
`batchID` INT(11) NOT NULL,
`batch_transaction_transactionID` INT(11) NULL,
`book_typeID` INT(11) NOT NULL,
`price` DECIMAL(10,2) NULL,
`supplierID` INT(11) NULL,
PRIMARY KEY (`batchID`),
INDEX `fk_batches_batch_transaction1_idx` (`batch_transaction_transactionID` ASC),
CONSTRAINT `fk_batches_batch_transaction1`
FOREIGN KEY (`batch_transaction_transactionID`)
REFERENCES `mydb`.`batch_transaction` (`transactionID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`book_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`book_types` (
`book_typeID` INT(11) NOT NULL,
`name` VARCHAR(255) NULL,
`book_productID` INT(11) NOT NULL,
`books_book_prices_book_priceID` INT(11) NOT NULL,
`books_book_types_book_typeID` INT(11) NOT NULL,
`batches_batchID` INT(11) NOT NULL,
PRIMARY KEY (`book_typeID`, `book_productID`, `books_book_prices_book_priceID`, `books_book_types_book_typeID`),
INDEX `fk_product_types_products1_idx` (`book_productID` ASC, `books_book_prices_book_priceID` ASC, `books_book_types_book_typeID` ASC),
INDEX `fk_product_types_batches1_idx` (`batches_batchID` ASC),
CONSTRAINT `fk_product_types_products1`
FOREIGN KEY (`book_productID` , `books_book_prices_book_priceID` , `books_book_types_book_typeID`)
REFERENCES `mydb`.`books` (`bookID` , `book_prices_book_priceID` , `book_types_book_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_product_types_batches1`
FOREIGN KEY (`batches_batchID`)
REFERENCES `mydb`.`batches` (`batchID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`suppliers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`suppliers` (
`supplierID` INT(11) NOT NULL,
`batches_batchID` INT(11) NOT NULL,
`name` VARCHAR(255) NULL,
PRIMARY KEY (`supplierID`),
INDEX `fk_suppliers_batches1_idx` (`batches_batchID` ASC),
CONSTRAINT `fk_suppliers_batches1`
FOREIGN KEY (`batches_batchID`)
REFERENCES `mydb`.`batches` (`batchID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`client_transaction`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`client_transaction` (
`transactionID` INT(11) NOT NULL,
`clientID` INT(11) NULL,
`transactions_transactionID` INT(11) NOT NULL,
`date` DATETIME NULL,
PRIMARY KEY (`transactionID`, `transactions_transactionID`),
INDEX `fk_client_transaction_transactions1_idx` (`transactions_transactionID` ASC),
CONSTRAINT `fk_client_transaction_transactions1`
FOREIGN KEY (`transactions_transactionID`)
REFERENCES `mydb`.`transactions` (`transactionID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`clients`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`clients` (
`clientID` INT(11) NOT NULL,
`books_bookID` INT(11) NULL,
`books_book_prices_book_priceID` INT(11) NOT NULL,
`books_book_types_book_typeID` INT(11) NOT NULL,
`client_transaction_transactionID` INT(11) NOT NULL,
PRIMARY KEY (`clientID`),
INDEX `fk_clients_products1_idx` (`books_bookID` ASC, `books_book_prices_book_priceID` ASC, `books_book_types_book_typeID` ASC),
INDEX `fk_clients_client_transaction1_idx` (`client_transaction_transactionID` ASC),
CONSTRAINT `fk_clients_products1`
FOREIGN KEY (`books_bookID` , `books_book_prices_book_priceID` , `books_book_types_book_typeID`)
REFERENCES `mydb`.`books` (`bookID` , `book_prices_book_priceID` , `book_types_book_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_clients_client_transaction1`
FOREIGN KEY (`client_transaction_transactionID`)
REFERENCES `mydb`.`client_transaction` (`transactionID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`discounts`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`discounts` (
`discountID` INT(11) NOT NULL,
`Name` VARCHAR(255) NOT NULL,
`transactions_transactionID` INT(11) NULL,
`transactions_transaction_types_transaction_typeID` INT(11) NULL,
PRIMARY KEY (`discountID`),
INDEX `fk_discounts_transactions1_idx` (`transactions_transactionID` ASC, `transactions_transaction_types_transaction_typeID` ASC),
CONSTRAINT `fk_discounts_transactions1`
FOREIGN KEY (`transactions_transactionID` , `transactions_transaction_types_transaction_typeID`)
REFERENCES `mydb`.`transactions` (`transactionID` , `transaction_types_transaction_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`discount_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`discount_types` (
`discount_typeID` INT(11) NOT NULL,
`Type` VARCHAR(255) NULL,
`discounts_discountID` INT(11) NOT NULL,
PRIMARY KEY (`discount_typeID`, `discounts_discountID`),
INDEX `fk_discount_types_discounts1_idx` (`discounts_discountID` ASC),
CONSTRAINT `fk_discount_types_discounts1`
FOREIGN KEY (`discounts_discountID`)
REFERENCES `mydb`.`discounts` (`discountID`)
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;
Что дает следующую ошибку:
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 ') VIRTUAL,
`name` VARCHAR(255) NULL,
`price` DECIMAL(10,2) NULL,
`book_pri' at line 5
SQL Code:
-- -----------------------------------------------------
-- Table `mydb`.`books`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`books` (
`bookID` INT(11) GENERATED ALWAYS AS () VIRTUAL,
`name` VARCHAR(255) NULL,
`price` DECIMAL(10,2) NULL,
`book_prices_book_priceID` INT(11) NOT NULL,
`book_types_book_typeID` INT(11) NOT NULL,
`transactions_transactionID` INT(11) NOT NULL,
`transactions_transaction_types_transaction_typeID` INT(11) NOT NULL,
`ISBN` VARCHAR(13) NULL,
PRIMARY KEY (`bookID`, `book_prices_book_priceID`, `book_types_book_typeID`),
INDEX `fk_products_product_prices1_idx` (`book_prices_book_priceID` ASC),
INDEX `fk_products_transactions1_idx` (`transactions_transactionID` ASC, `transactions_transaction_types_transaction_typeID` ASC) ,
CONSTRAINT `fk_products_product_prices1`
FOREIGN KEY (`book_prices_book_priceID`)
REFERENCES `mydb`.`book_prices` (`book_priceID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_products_transactions1`
FOREIGN KEY (`transactions_transactionID` , `transactions_transaction_types_transaction_typeID`)
REFERENCES `mydb`.`transactions` (`transactionID` , `transaction_types_transaction_typeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 8 succeeded, 1 failed