-1

我有两个表如下

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

有任何想法吗?

4

1 回答 1

2

试试这个代码

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

这是Oracle关于约束的文档的链接以供参考

于 2013-05-22T13:31:31.713 回答