我创建了一个表ASSIGNMENTS:
CREATE TABLE assignments (
id_project NUMBER(4) NOT NULL CONSTRAINT fk_assignments_01 REFERENCES projects (id_project),
empl_number NUMBER(6) NOT NULL CONSTRAINT fk_assignments_02 REFERENCES employees (empl_id),
start DATE DEFAULT SYSDATE,
end DATE,
CONSTRAINT chk_assignements_dates CHECK (end > start),
rate NUMBER(7, 2),
CONSTRAINT chk_assignements_rate CHECK (rate > 0),
role VARCHAR2(20),
CONSTRAINT chk_assignements_role CHECK (rola IN ('ANALYST', 'DEVELOPER'))
);
现在我必须修改约束fk_assignments_02。我想设置fk_assignments_02 ON DELETE CASCADE。我试着这样做:
ALTER TABLE assignments
MODIFY id_project NUMBER(4) NOT NULL CONSTRAINT fk_assignments_01 REFERENCES projects (id_project) ON DELETE CASCADE;
但是我收到一个错误: ORA-02275:表
中已经存在这样的引用约束答案 0 :(得分:2)
你不能这样做 - 你必须放弃并重新添加约束。 Oracle中没有规定更改ON DELETE
操作,这是REFERENCES
子句的一部分,而不是约束状态的一部分。
所以要完成这个,你需要做
ALTER TABLE ASSIGNMENTS DROP CONSTRAINT FK_ASSIGNMENTS_02;
接着是
ALTER TABLE ASSIGNMENTS
ADD CONSTRAINT FK_ASSIGNMENTS_02
FOREIGN KEY (ID_PROJECT) REFERENCES PROJECT (ID_PROJECT)
ON DELETE CASCADE;
祝你好运。