慢插入SQL Server表

时间:2016-11-08 03:26:26

标签: sql sql-server database sql-server-2008

enter image description here

enter image description here

与具有4GB内存的本地数据库相比,缓慢插入我的SQL Server表的原因是什么原因在我的客户端服务器上运行时间少于2秒的脚本(1g内存)(附加图像)花了50秒。

以下是一个示例查询,来自我本地和客户端数据库的记录几乎相同。

IF OBJECT_ID('tempdb..#TempUnitServiceLogs') IS NOT NULL
    drop table #TempUnitServiceLogs

Select 
    F.Unit_Id, MAX(F.UnitTransaction_Id) UnitTransaction_Id 
into 
    #TempUnitServiceLogs
from 
    TempUnitServiceLogs F 
group by  F.Unit_Id



insert into TempUnitServiceLogs
    Select 
        A.Unit_Id
        ,C.Brand_Name
        ,A.Unit_CompanyCode
        ,B.Project_Code
        ,A.Unit_Code 
        ,A.Unit_Status  

    from  Table1 A
    inner join Table2 B on A.Project_Id = B.Project_Id
    inner join Table3 C on B.Brand_Id = C.Brand_Id
    left join #TempUnitServiceLogs D on A.Unit_Id = D.Unit_ID
    left join Table4 ut on ut.Unit_Id = A.Unit_Id
    left join Table5 pb on pb.ProspectiveBuyer_Id = ut.ProspectiveBuyer_Id  
    where 1=1 
      and d.UnitTransaction_Id IS NULL
      and case when UnitTransaction_ModDate IS null 
        then convert(date,UnitTransaction_CrDate) 
      else convert(date,UnitTransaction_ModDate) end = CONVERT(date,GETDATE())

0 个答案:

没有答案