主表: product_types
从表: products alter table products add constraint fk_products_type_id foreign key(product_type_id) references product_types(product_type_id) ON DELETE CASCADE;想实现删主表一记录时, 同时删除子表中对应的记录. 不想用触发器.
外键已经加了 ON DELETE CASCADE.
但是删主表记录时, 主表的记录删了, 但是从表的却没有删? 为什么? 

解决方案 »

  1.   

    if exists(select 1 from products where 外键 = 某值)
       delete products where 外键 = 某值delete product_types where 外键 = 某值   
      

  2.   

    应该可以啊,你的ORACLE是什么VERSION?.
        [align=center]====  ====
    [/align]
    .
    贴子分数<20:对自已的问题不予重视。
    贴子大量未结:对别人的回答不予尊重。
    .
      

  3.   

    win Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
      

  4.   

    http://space.itpub.net/10742223/viewspace-237971
      

  5.   

    lz就是这么做的
    会不会是你的oracle不是自动提交?
      

  6.   

    按道理应该是可以的,我这里没问题:
    11:09:23 SQL> desc t4;
     名称                                      是否为空? 类型
     ----------------------------------------- -------- ---------------------------- RN                                                 NUMBER11:09:26 SQL> alter table t4 modify rn primary key;表已更改。11:31:12 SQL> create table t5(rn number,foreign key (rn) references t4(rn) on de
    lete cascade);表已创建。11:31:42 SQL> insert into t5 values(1);已创建 1 行。11:31:54 SQL> insert into t5 values(1);已创建 1 行。11:31:55 SQL> insert into t5 values(2);已创建 1 行。11:31:57 SQL> insert into t5 values(10);已创建 1 行。11:32:00 SQL> commit;提交完成。11:32:18 SQL> delete from t4 where rn=1;已删除 1 行。11:32:27 SQL> commit;提交完成。11:32:39 SQL> select * from t5;        RN
    ----------
             2
            1011:32:42 SQL>
      

  7.   

    我也想用sql实现级联删除,该怎么写呢。