ALTER TABLE "U_WEN_BOOK"."GCHILTAB1"
DROP CONSTRAINT "FK_G1"
ALTER TABLE "U_WEN_BOOK"."GCHILTAB1"
ADD (CONSTRAINT "FK_G1" FOREIGN KEY()
REFERENCES "U_WEN_BOOK"."CHILTAB"()
ON DELETE CASCADE)
(这样就可以级联删除了,删除完后,如果不放心这样的约束条件,并且不嫌麻烦可以再重建为不带级联删除等外键约束,防止误操作)
create table orderCombine (
O_Id VARCHAR2(16) not null,
OrderId VARCHAR2(15) not null,
FormerId VARCHAR2(16) not null,
constraint PK_ORDERCOMBINE primary key (FormerId) );
create table VIPForm (
V_Id VARCHAR2(16) not null,
IsValid CHAR(1) default '0' not null ,
Constraint fk_vipform foreign key(V_id) references ordercombine(formerid) );
insert into orderCombine values('1','1','1'); insert into orderCombine values('2','2','2'); insert into vipform values('1','5'); insert into vipform values('2','4'); insert into vipform values('1','2');
结果:
(2)创建触发器: SQL:
CREATE OR REPLACE TRIGGER "FG123"."TER_OV"
BEFORE
DELETE ON "ORDERCOMBINE" FOR EACH ROW
BEGIN
DELETE FROM VIPForm
WHERE VIPForm.V_Id=:OLD.FormerId;
END;
(3)删除及结果: SQL:
DELETE FROM "FG123"."ORDERCOMBINE"
WHERE FormerId ='1'