日期:2014-05-18 浏览次数:20373 次
--版本是SQL2000 --数据量都不大,几万条,但是执行非常慢,要几分钟。。 --怎么优化呢 UPDATE T_BASE_PARTSALF SET CURRSALF = T1.SAFENUM, UPDATETIME=ISNULL(CONVERT(DATETIME,T1.UPDATETIME),GETDATE()), UPDATEMAN='SYSMAN' FROM ( SELECT IOSF.SAFENUM,IOSF.UPDATETIME,PART.PARTID,FACT.FACTID FROM T_IO_SAFESTORAGE IOSF LEFT JOIN T_BASE_PART PART ON IOSF.PARTCODEU8=PART.PARTCODE LEFT JOIN T_BASE_FACT FACT ON IOSF.FACTCODE=FACT.FACTCODE WHERE ISACTIVE=1) AS T1 WHERE T_BASE_PARTSALF.PARTID = T1.PARTID AND T_BASE_PARTSALF.FACTID=T1.FACTID
;WITH T AS( SELECT IOSF.SAFENUM,IOSF.UPDATETIME,PART.PARTID,FACT.FACTID FROM T_IO_SAFESTORAGE IOSF LEFT JOIN T_BASE_PART PART ON IOSF.PARTCODEU8=PART.PARTCODE LEFT JOIN T_BASE_FACT FACT ON IOSF.FACTCODE=FACT.FACTCODE WHERE ISACTIVE=1 ) UPDATE T_BASE_PARTSALF SET CURRSALF = T.SAFENUM, UPDATETIME=ISNULL(CONVERT(DATETIME,T1.UPDATETIME),GETDATE()), UPDATEMAN='SYSMAN' FROM T WHERE T_BASE_PARTSALF.PARTID = T1.PARTID AND T_BASE_PARTSALF.FACTID=T1.FACTID 这样试试,还有where后面的字段加索引