Oracle - 在删除/开启更新时

时间:2018-01-23 10:51:43

标签: database oracle

我有另一个名为Users的表,当我在这里执行此代码时:

create table Borrow(
bookID int,
memberID int,
dayOfBorrowed date not null,
dayToReturn date not null,
giverUser int not null,
CONSTRAINT check_dayToReturn check(dayToReturn>dayOfBorrowed),
primary key (bookID, memberID),
foreign key (bookID) references Books(bookID) on delete cascade,
foreign key (memberID) references Members(memberID) on delete cascade, 
foreign key (giverUser) references Users(userID) on update no action on delete no action);

我收到此错误

> Error starting at line : 72 in command - create table Borrow( bookID
> int, memberID int, dayOfBorrowed date not null, dayToReturn date not
> null, giverUser int not null, CONSTRAINT check_dayToReturn
> check(dayToReturn>dayOfBorrowed), primary key (bookID, memberID),
> foreign key (bookID) references Books(bookID) on delete cascade,
> foreign key (memberID) references Members(memberID) on delete cascade,
> foreign key (giverUser) references Users(userID) on update no action on delete no action)
> Error report - ORA-00905: missing keyword
> 00905. 00000 -  "missing keyword"
> *Cause:    
> *Action:

有人可以向我解释我在这里做错了吗?

2 个答案:

答案 0 :(得分:2)

我们doc

references_clause

REFERENCES [ schema. ] object [ (column [, column ]...) ]
  [ON DELETE { CASCADE | SET NULL } ]

换句话说,Oracle没有ON UPDATE功能,因此甚至不需要ON UPDATE NO ACTION

P.S。您可能希望找到一个内置SQL解析的工具:

JetBrains

答案 1 :(得分:0)

on update没有foreign key references选项。

问题源于此引用(最后)行。

删除

  

on update no action on delete no action

一部分。

您可以使用on delete cascadeon delete set null,但不能使用on delete no action条款。