现在业务生产系统累计了大量的数据,数据库为sql server2000,由于数据量越来越大,系统运行缓慢,现在要求把指定时间之前,库存量为0的数据全部导出来,但是还是能够查询的,而且要把和库存关联的表都到处来,这么该怎么做,怎么实现呢

解决方案 »

  1.   

    不知你要结转几个表大致思路:
    --1.新建表结构(复制出入库表的结构)select * into 出入库表_old from 出入库表 where 1=0--2.填充增经发生过但库存为零的数据到刚建的表:
    insert 出入库表_old select * from 出入库表 t where not exists(select 1 from 库存表 where 物料编码=t.物料编码)--3.删除出入库表库存为0的数据:
    delete 出入库表 where not exists not exists(select 1 from 库存表 where 物料编码=出入库表.物料编码)
      

  2.   

    --3.删除出入库表库存为0的数据:
    delete 出入库表 where not exists(select 1 from 库存表 where 物料编码=出入库表.物料编码)手误多了个not exists