表間的關系比較復雜
方法一
(但一般由於各種原因或出於各種考慮在創建數據庫時沒有設定級聯刪除)
SQL語句
CREATE TABLE "U_WEN_BOOK"
"FAR_NAME" VARCHAR
CONSTRAINT "PK_FER" PRIMARY KEY("FAR_ID"))
CREATE TABLE "U_WEN_BOOK"
NULL
"FAR_ID" NUMBER(
CONSTRAINT "PK_CHIL" PRIMARY KEY("CHIL_ID")
CONSTRAINT "FK_CHIL" FOREIGN KEY("FAR_ID")
REFERENCES "U_WEN_BOOK"
方法二
(實驗證明完全可行
SQL語句
ALTER TABLE "U_WEN_BOOK"
DROP CONSTRAINT "FK_G
ALTER TABLE "U_WEN_BOOK"
ADD (CONSTRAINT "FK_G
REFERENCES "U_WEN_BOOK"
ON DELETE CASCADE)
(這樣就可以級聯刪除了
方法三
(比較靈活
(
SQL語句
create table orderCombine (
O_Id VARCHAR
OrderId VARCHAR
FormerId VARCHAR
constraint PK_ORDERCOMBINE primary key (FormerId) );
create table VIPForm (
V_Id VARCHAR
IsValid CHAR(
Constraint fk_vipform foreign key(V_id) references ordercombine(formerid) );
insert into orderCombine values(
結果
(
SQL
CREATE OR REPLACE TRIGGER "FG
BEFORE
DELETE ON "ORDERCOMBINE" FOR EACH ROW
BEGIN
DELETE FROM VIPForm
WHERE VIPForm
END;
(
SQL
DELETE FROM "FG
WHERE FormerId =
方法四
(前面的方法在涉及數據量較大以及表間關系比較復雜時才有效率上的優勢
如上例中
SQL語句
DELETE FROM "FG
WHERE VIPForm =
DELETE FROM "FG
WHERE FormerId =
From:http://tw.wingwit.com/Article/program/Oracle/201311/19027.html