“关键字'ON'附近的语法不正确。(在更新级联上,在删除级联上,)

时间:2018-11-23 14:16:33

标签: mysql

对不起,对您的帮助我们深表感谢。 我不断收到这种“关键字“ ON”附近的语法不正确”的信息。 这是我的密码

代码一

CREATE TABLE supplier (
supplierID INT PRIMARY KEY,
ISBN INT FOREIGN KEY REFERENCES book(ISBN),
price DECIMAL (5,2),
ON UPDATE CASCADE,
ON DELETE CASCADE,
);

代码二

CREATE TABLE orders (
orderID INT PRIMARY KEY,
customerID INT FOREIGN KEY REFERENCES customer(customerID),
ISBN INT FOREIGN KEY REFERENCES book(ISBN),
orderDate date,
ON UPDATE CASCADE,
ON DELETE CASCADE,
);

我已经用光了东西,除了将其愚弄成无用之物。

1 个答案:

答案 0 :(得分:0)

ON UPDATEON DELETE应该位于外键定义之外,而不是远离外键定义。另外,每个外键定义都将具有自己的ON UPDATEON DELETE定义。

CREATE TABLE supplier (
supplierID INT PRIMARY KEY,
ISBN INT FOREIGN KEY REFERENCES book(ISBN) 
  ON UPDATE CASCADE 
  ON DELETE CASCADE,
price DECIMAL (5,2)
);


CREATE TABLE orders (
orderID INT PRIMARY KEY,
customerID INT FOREIGN KEY REFERENCES customer(customerID)
  ON UPDATE CASCADE
  ON DELETE CASCADE,
ISBN INT FOREIGN KEY REFERENCES book(ISBN)
  ON UPDATE CASCADE
  ON DELETE CASCADE,
orderDate date
);