现在有两个表,table1,table2,我想两个表关联同时删除table1,table2中的数,table1.creattime<10月份的,table2.vchid=table1.vchid的数据,是两个表同时删除,这样的SQL要怎样写呢?

解决方案 »

  1.   

    必须要2个sql才能办到。
    delete from table1 where table1.createtime<to_date('2009-10-1','YYYY-MM-DD') and exists (select 1 from table2 where table1.vchid=table2.vchid) 
      

  2.   

    1、用触发器实现2、写2个sql语句
      

  3.   

    应该重建带级联删除的约束
    ON DELETE CASCADE
    找到篇文章,希望对你有帮助
    http://www.51testing.com/?uid-182741-action-viewspace-itemid-95001
    http://www.diybl.com/course/7_databases/oracle/oraclejs/2008828/138126.html#
      

  4.   

    没有办法。
    如楼上各位所说。总结一下1。两个SQL DELETE语句,可以放在一个事务中。
    2。 使用触发器。
    3。直接设计外键的 on delete cascade 
      

  5.   

    1。两个SQL DELETE语句,可以放在一个事务中。 
    2。 使用触发器。 
    3。直接设计外键的 on delete cascade 
      

  6.   

    必须2个sql,delete和update好像不能同时对两个及以上的表操作。