我有两张表格如下
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
有什么想法吗?
答案 0 :(得分:2)
试试这段代码
ALTER TABLE "RESERVATION"
ADD CONSTRAINT "RESERVATION_CLIENT_FK"
FOREIGN KEY ("CLIENT_ID")
REFERENCES "CLIENT" ("ID")
ON DELETE CASCADE;
以下是有关constraint的Oracle文档的链接以供参考