数据库设计 2019-04-03
代码如下:
CREATE TABLE "U_WEN_BOOK"."FARTAB" ("FAR_ID" NUMBER(10) NOT NULL, "FAR_NAME" VARCHAR2(10), "OTHER_NAME" VARCHAR2(10), CONSTRAINT "PK_FER" PRIMARY KEY("FAR_ID")) CREATE TABLE "U_WEN_BOOK"."CHILTAB" ("CHIL_ID" NUMBER(10) NOT NULL, "CHIL_NAME" VARCHAR2(10), "CHIL_OTHER" VARCHAR2(10), "FAR_ID" NUMBER(10) NOT NULL, CONSTRAINT "PK_CHIL" PRIMARY KEY("CHIL_ID"), CONSTRAINT "FK_CHIL" FOREIGN KEY("FAR_ID") REFERENCES "U_WEN_BOOK"."FARTAB"("FAR_ID") ON DELETE CASCADE)
代码如下:
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');
代码如下:
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;
代码如下:
DELETE FROM "FG123"."ORDERCOMBINE" WHERE FormerId ='1'
代码如下:
DELETE FROM "FG123"."ORDERCOMBINE" WHERE VIPForm ='1'; DELETE FROM "FG123"."ORDERCOMBINE" WHERE FormerId ='1'