简体   繁体   English

当我无法发现问题时,如何解决 SQL ERROR 1604 语法错误?

[英]How to resolve SQL ERROR 1604 Syntax error when I can't spot the issue?

I'm new to all of this and I am struggling to spot where the error in my syntax is for creating sql tables, any support is greatly appreciated:我是这一切的新手,我正在努力找出我的语法错误在哪里用于创建 sql 表,非常感谢任何支持:

The error I am recieving is :我收到的错误是:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
REFERENCES ims.orders ()
ON DELETE CASCADE
ON UPDATE CASCADE,
CO' at line 8

Which comes from running this code snippet:这来自运行此代码片段:

   CREATE TABLE IF NOT EXISTS `ims`.`orderline` (
  `olid` INT NOT NULL AUTO_INCREMENT,
  `oid` INT NOT NULL,
  `iid` INT NOT NULL,
  `quantity` INT NOT NULL,
  PRIMARY KEY (`olid`),
  CONSTRAINT `oid`
    FOREIGN KEY ()
    REFERENCES ims.orders ()
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `iid`
    FOREIGN KEY ()
    REFERENCES ims.items ()
    ON DELETE CASCADE
    ON UPDATE CASCADE
);

From the database created with this schema:从使用此架构创建的数据库中:

drop schema ims;
CREATE SCHEMA IF NOT EXISTS `ims`;
USE `ims` ;
CREATE TABLE IF NOT EXISTS `ims`.`customers` (
    `cid` INT(11) NOT NULL AUTO_INCREMENT,
    `first_name` VARCHAR(40) NULL DEFAULT NULL,
    `surname` VARCHAR(40) NULL DEFAULT NULL,
    PRIMARY KEY (`cid`)
);
CREATE TABLE IF NOT EXISTS `ims`.`items` (
    `iid` INT(11) NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(40) NULL DEFAULT NULL,
    `price` DECIMAL(10,2) NOT NULL,
    PRIMARY KEY (`iid`)
);
CREATE TABLE IF NOT EXISTS `ims`.`orders` (
    `oid` INT(11) NOT NULL AUTO_INCREMENT,
    `cid`INT(11) NOT NULL,
    FOREIGN KEY (cid) REFERENCES ims.customers (cid)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
    PRIMARY KEY (`oid`)
);
CREATE TABLE IF NOT EXISTS `ims`.`orderline` (
`olid` INT NOT NULL AUTO_INCREMENT,
`oid` INT NOT NULL,
`iid` INT NOT NULL,
`quantity` INT NOT NULL,
PRIMARY KEY (`olid`),
CONSTRAINT `oid_fk`
  FOREIGN KEY (`oid`)
  REFERENCES ims.orders (oid)
  ON DELETE CASCADE
  ON UPDATE CASCADE,
CONSTRAINT `iid_fk`
  FOREIGN KEY (`iid`)
  REFERENCES ims.items (iid)
  ON DELETE CASCADE
  ON UPDATE CASCADE
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM