对不起,对您的帮助我们深表感谢。 我不断收到这种“关键字“ 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,
);
我已经用光了东西,除了将其愚弄成无用之物。
答案 0 :(得分:0)
ON UPDATE
和ON DELETE
应该位于外键定义之外,而不是远离外键定义。另外,每个外键定义都将具有自己的ON UPDATE
和ON 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
);