更新問題
Update FileInfo Set CancelExpert=1,CAID=1 From
(Select a.fileid,a.rev from (select Fileid,Rev from Relationfile where
Relationfile.Nodeid =26535) as a, (Select fileid,rev from Relationfile group by
fileid,rev having count(*)=1) as b where a.fileid=b.fileid and a.rev=b.rev) as c
Where fileinfo.fileid=c.fileid and fileinfo.rev=c.rev AND (FileInfo.[FILEName] like 'Part%List% '
or FileInfo.[FILEName] like '生產工藝規格% ' or FileInfo.[FILEName] like '生產效率排拉圖% ' or
FileInfo.[FILEName] like '作業指導卡% ' or FileInfo.[FILEName] like '馬達出廠檢驗規格% ' or
FileInfo.[FILEName] like '馬達外型圖% ' or FileInfo.[FILEName] like '馬達技術參數% ' or
FileInfo.[FILEName] like '包裝示意圖% ' or FileInfo.[FILEName] like '控制計劃% ' or
FileInfo.[FILEName] like '檢查標準% ' or FileInfo.[FILEName] like '機模夾具對照表% ')
以上更新語句更新速度很慢,更新一條都至少要40多秒,我有幾千條記錄,如果這樣慢,不知要到什麼時候才更新完,
哪位高手可以幫忙優化下這條語句
------解决方案--------------------这么多的like 肯定很慢了!
可以建个临时表,把那些Like出的数据放在这里,然后根据临时表再Update
------解决方案--------------------關鍵是or的問題
------解决方案--------------------这样试试
Update FileInfo
Set CancelExpert=1,CAID=1
From
(select Fileid,Rev from Relationfile where
Relationfile.Nodeid =26535 group by fileid,rec having count(*)=1) as a
Where fileinfo.fileid=a.fileid
and fileinfo.rev=a.rev
AND (FileInfo.[FILEName] like 'Part%List% '
or (FileInfo.[FILEName] like '生產工藝規格% ' or FileInfo.[FILEName] like '生產效率排拉圖% ' or
FileInfo.[FILEName] like '作業指導卡% ' or FileInfo.[FILEName] like '馬達出廠檢驗規格% ' or
FileInfo.[FILEName] like '馬達外型圖% ' or FileInfo.[FILEName] like '馬達技術參數% ' or
FileInfo.[FILEName] like '包裝示意圖% ' or FileInfo.[FILEName] like '控制計劃% ' or
FileInfo.[FILEName] like '檢查標準% ' or FileInfo.[FILEName] like '機模夾具對照表% '))
------解决方案--------------------FileInfo.[FILEName] like 'Part%List% '只有这个like影响速度,其他的不会影响,建议单独拿出来UPDATE....
------解决方案--------------------有两个子查询是多余的,可以整体合为一个.
感觉你where后的条件有问题,先是and,后面都是or,如果其中一个or符合的话整个where就符合了,而且两表关联条件都不起作用,应该在and后将整个or用括号括起来
------解决方案--------------------抱歉,更正一下,表别名用错了:
Update a Set CancelExpert=1,CAID=1 From FileInfo AS a
INNER JOIN
(select Fileid,Rev from Relationfile where Nodeid =26535
group by fileid,rev having count(*)=1) AS c
ON a.fileid=c.fileid AND a.rev=c.rev
AND (
a.[FILEName] like 'Part%List% '
or a.[FILEName] like '生產工藝規格% ' or a.[FILEName] like '生產效率排拉圖% ' or
a.[FILEName] like '作業指導卡% ' or a.[FILEName] like '馬達出廠檢驗規格% ' or
a.[FILEName] like '馬達外型圖% ' or a.[FILEName] like '馬達技術參數% ' or