数据库有这样一个表customer,结构如下:类型       字段  
int        id     自增,但可能不连续,有删除过一些记录
varchar    custName
varchar    address
将上面表中的数据复制到customer111表中
int        id
varchar    custName
varchar    address
int        Imp_id    这字段记录customer表中id的值当删除customer某些记录时,如何做到同步更新到customer111表中,把customer111中的Imp_id 与 customer中的id 作对比,删除记录假设已经把customer表中的id值 存放在字符串str中,并已逗号隔开是否可以使用
delete from customer111 where Imp_id .......或者其他办法

解决方案 »

  1.   

    你的customer表中最好有個單獨的customerid來唯一標識每條記錄,然后每次刪除根據這個id,實際上是以他為主鍵,別用自增的id了,刪除customer表中記錄同時,看看customer111中有沒有這個id的記錄,有的話也可以同步刪除了,添加和修改都是一樣的了
      

  2.   

    当删除customer某些记录时,如何做到同步更新到customer111表中,把customer111中的Imp_id 与 customer中的id 作对比,删除记录 删除customer,customer111中的记录要放在一个事务中
    delete from customer111 where Imp_id in (?)
      

  3.   

    oracle建表的时候在第二个表的那个外键里添加ON DELETE CASCADE,级联删除
    用hibernate的话就是弄一个<one-to-one>然后cascade="all"或者cascade="Delete"