我在存储过程中有以下查询:
UPDATE dbo.CRM_tblActivityStore
SET StoDateChngFlg = CASE
WHEN x.STAGE_STAD <> x.ACTSTR_STAD THEN 1 ELSE 0 END
FROM (SELECT CASE
WHEN sd.stad = '00000000' THEN '12-31-2049' ELSE CONVERT (DATE, sd.stad)
END AS STAGE_STAD,
CONVERT (DATE, tas.StoDateSTA) AS ACTSTR_STAD,
tas.StoActivityNbr,
sd.Proj_Code,
sd.OrderNbr,
sd.FileNbr
FROM [SCM Server].[OrdrMgmt].dbo.STAGE_StageData AS sd
INNER JOIN
dbo.CRM_tblActivityStore AS tas
ON sd.Proj_Code = tas.StoProjCode
AND sd.OrderNbr = tas.StoOrderNbr
AND sd.FileNbr = tas.StoFile) AS x
INNER JOIN
dbo.CRM_tblActivityStore AS tast
ON tast.StoActivityNbr = x.StoActivityNbr
AND tast.StoProjCode = x.Proj_Code
AND tast.StoOrderNbr = x.OrderNbr
AND tast.StoFile = x.FileNbr;
一些可能有帮助的更多信息:
[SCM 服务器].[OrdrMgmt].dbo.STAGE_StageData - 超过 2,000,000 行 dbo.CRM_tblActivityStore - 超过 5,000,000 行
这些表都没有索引,也没有主键。
这个需要3个多小时。
添加索引可以提高多大的效率?
任何其他想法如何改进它?
谢谢,
宜兰