“缺少右括号”:在更新级联上删除设置为空(SQL / Oracle)

时间:2014-01-19 01:16:35

标签: sql oracle

我有(另一个?)'缺少右括号'错误。

我对SQL完全不熟悉,所以我真的不太清楚问题是什么。

实际上,它似乎不是一个缺失的括号。但是我不断地在“ON DELETE SET NULL ON UPDATE CASCADE”行上抛出错误。

我真的很感激有任何帮助来确定问题所在。

我正在使用Oracle 11g Express运行我的.sql文件。

CREATE TABLE Hotel
(hotelNo          CHAR(10)          NOT NULL
,hotelName        VARCHAR2(50)      NOT NULL
,city             VARCHAR2(50)      NOT NULL
,CONSTRAINT PKHotel PRIMARY KEY (hotelNo)
);
--
CREATE TABLE Room
(roomNo           CHAR(3)           NOT NULL
,hotelNo          CHAR(10)          NOT NULL
,roomType         VARCHAR2(20)      NOT NULL
,price            DECIMAL(6,2)      NOT NULL
,CONSTRAINT checkRoomNo CHECK (roomNo BETWEEN 1 AND 100)
,CONSTRAINT checkType CHECK (roomType IN ('Single', 'Double', 'Family'))
,CONSTRAINT checkPrice CHECK (price BETWEEN 10.00 AND 100.00)
,CONSTRAINT PKRoom PRIMARY KEY (roomNo, hotelNo)
,CONSTRAINT FKHotel FOREIGN KEY (hotelNo) REFERENCES Hotel(hotelNo)
    ON DELETE SET NULL ON UPDATE CASCADE
);
--

非常感谢。我真的很感激!

1 个答案:

答案 0 :(得分:1)

在Oracle中无法进行更新级联。汤姆凯特说:

There is not "on update cascade" automagically.

There are ways to do it, 

o deferrable constraints.  defer the foreign key check until commit, update the parent, 
update the child and then commit.

Personally -- I've never found a need or use for update cascade.  I'm opposed to it.  If 
your design requires it -- change your design now if you can.  


Primary keys are supposed to be imutable, never changing, constant.  It is an excessively 
bad practice to have to update them ever.  If there is a 0.00001% chance you will have to 
update a primary key -- then it is not a primary key, its a surrogate key and you need to 
find the true primary key (even if you have to make it up via a sequence) 

选中此link