试在相关字段加索引,如:
create clustered index idx_groupid on fs_temp_fix(groupid)

解决方案 »

  1.   

    既然两个表中相同的记录插入fs_temp_fix表
    那也就是说fs_temp_fix表中有记录了,还插入干嘛?
      

  2.   

    你用如下两句再试试.(建议对LINKMAN_PHONE,SOCIAL_ID等建立索引)insert dbo.fs_temp_fix 
    select distinct a.*,b.groupid,2,0,0 from dbo.fs_temp_nonefix a,fs_temp_fix b
    where (ISNUMERIC(a.LINKMAN_PHONE)=1 and a.LINKMAN_PHONE =b.LINKMAN_PHONE) or (a.SOCIAL_ID =b.SOCIAL_ID)insert dbo.fs_temp_fix 
    select a.*,b.groupid,2,0,0 from dbo.fs_temp_nonefix a,fs_temp_fix b
    where (ISNUMERIC(a.LINKMAN_PHONE)=1 and a.LINKMAN_PHONE =b.LINKMAN_PHONE) or (a.SOCIAL_ID =b.SOCIAL_ID)
      

  3.   


    ALTER procedure [dbo].[sp_e9_model_table_2]
    as
    begin
    if exists (select name from sysobjects where type='u' and name ='fs_temp_fix_1')
     begin
     truncate table fs_temp_fix_1
     drop table fs_temp_fix_1
     end
    select * into fs_temp_fix_1 from fs_temp_fix where 1=2insert into fs_temp_fix_1
    select distinct a.*,b.groupid,1,0,0 from dbo.fs_temp_nonefix a,fs_temp_fix b
    where a.SOCIAL_ID =b.SOCIAL_ID and a.serv_id not in(select fix1.serv_id from fs_temp_fix_1 fix1)
    union
    select distinct a.*,b.groupid,2,0,0 from dbo.fs_temp_nonefix a,fs_temp_fix b
    where ISNUMERIC(a.LINKMAN_PHONE)=1 and a.LINKMAN_PHONE =b.LINKMAN_PHONE and a.SOCIAL_ID <>b.SOCIAL_ID
    and a.serv_id not in(select fix2.serv_id from fs_temp_fix_1 fix2)--------将结果追加到[fs_temp_fix]表
    insert into [fs_temp_fix] select * from [fs_temp_fix_1]
    end
    我用的是上面这个,
    楼上的select a.*,b.groupid,2,0,0 ,这里这个2是a.LINKMAN_PHONE =b.LINKMAN_PHONE时候为2,而a.SOCIAL_ID =b.SOCIAL_ID的时候则为1哦
      

  4.   


    ALTER procedure [dbo].[sp_e9_model_table_2]
    as
    begin
    if exists (select name from sysobjects where type='u' and name ='fs_temp_fix_1')
     begin
     truncate table fs_temp_fix_1
     drop table fs_temp_fix_1
     end
    select * into fs_temp_fix_1 from fs_temp_fix where 1=2insert into fs_temp_fix_1
    select distinct a.*,b.groupid,1,0,0 from dbo.fs_temp_nonefix a,fs_temp_fix b
    where a.SOCIAL_ID =b.SOCIAL_ID and a.serv_id not in(select fix1.serv_id from fs_temp_fix_1 fix1)
    union
    select distinct a.*,b.groupid,2,0,0 from dbo.fs_temp_nonefix a,fs_temp_fix b
    where ISNUMERIC(a.LINKMAN_PHONE)=1 and a.LINKMAN_PHONE =b.LINKMAN_PHONE and a.SOCIAL_ID <>b.SOCIAL_ID
    and a.serv_id not in(select fix2.serv_id from fs_temp_fix_1 fix2)--------将结果追加到[fs_temp_fix]表
    insert into [fs_temp_fix] select * from [fs_temp_fix_1]
    end
    我用的是上面这个,
    楼上的select a.*,b.groupid,2,0,0 ,这里这个2是a.LINKMAN_PHONE =b.LINKMAN_PHONE时候为2,而a.SOCIAL_ID =b.SOCIAL_ID的时候则为1哦
      

  5.   

    还有就是这里的对LINKMAN_PHONE,SOCIAL_ID适合建立索引吗
    我对索引不熟悉,不太会哦,请指教
      

  6.   

    如果觉得速度慢,可以考虑建立索引.
    但是,你又是在fs_temp_fix表插入数据,即查询又插入,建立索引后,查询加块,插入减慢,确实比较矛盾,你自己权衡吧.
      

  7.   

    郁闷了,服务器根本就跑不动,我重新启动SQL服务,也确定了就只有我一个人在用SQL,我还什么都没跑,为什么我的内存在启动SQL服务以后就一直彪升啊,直到基本4G内存都用满的时候才停下来,好几次了,sqlserver.exe都是停止在1.7G的内存上,是不是这个原因,导致我上面的存储过程跑大半天都没反映啊,这是为什么呢????
      

  8.   

    --可以F1下
    MERGE INTO --的用法