2013-05-22 193 views
-1

我有兩個表如下的Oracle SQL ALTER TABLE

CREATE TABLE "CLIENT" 
("ID" NUMBER(*,0) NOT NULL ENABLE, 
"FIRSTNAME" VARCHAR2(255 CHAR), 
"LASTNAME" VARCHAR2(255 CHAR), 
"TELEPHONE" VARCHAR2(255 CHAR), 
CONSTRAINT "CLIENT_PK" PRIMARY KEY ("ID")) 

CREATE TABLE "BCR"."RESERVATION" 
("ID" NUMBER(*,0) NOT NULL ENABLE, 
"MYDATE" DATE, 
"USERS_ID" NUMBER(*,0) NOT NULL ENABLE, 
"CLIENT_ID" NUMBER(*,0), 
CONSTRAINT "RESERVATION_PK" PRIMARY KEY ("ID"), 
CONSTRAINT "RESERVATION_USER_FK" FOREIGN KEY ("USERS_ID") 
REFERENCES "USERS" ("ID")) 

我需要通過使用此代碼(我想補充ON DELETE CASCADE)

ALTER TABLE "RESERVATION" 
ADD CONSTRAINT "RESERVATION_CLIENT_FK" 
FOREIGN KEY ("CLIENT_ID") 
REFERENCES "CLIENT" CONSTRAINT "CLIENT_PK" PRIMARY KEY ("ID") 
ON DELETE CASCADE; 

然而,收到此錯誤修改表

SQL Error: ORA-01735: invalid ALTER TABLE option 

任何想法?

回答

2

試試這個代碼

ALTER TABLE "RESERVATION" 
ADD CONSTRAINT "RESERVATION_CLIENT_FK" 
FOREIGN KEY ("CLIENT_ID") 
REFERENCES "CLIENT" ("ID") 
ON DELETE CASCADE; 

這裏是鏈接到Oracle對constraint文檔參考

+0

謝謝!有用! – user2363971

+0

太好了。樂於幫助。 –