update dbo.fong_hc
Set dbo.fong_hc.ybbj = 1
from (select QCID,ybbj from dbo.fong_temphc) as tb
where dbo.fong_hc.qcid=tb.qcid and tb.ybbj=1dbo.fong_hc有66万多记录,dbo.fong_temphc的记录数可能在1到500
这样一个更新执行不完,超时,请问为什么?有什么改进方法吗?
Set dbo.fong_hc.ybbj = 1
from (select QCID,ybbj from dbo.fong_temphc) as tb
where dbo.fong_hc.qcid=tb.qcid and tb.ybbj=1dbo.fong_hc有66万多记录,dbo.fong_temphc的记录数可能在1到500
这样一个更新执行不完,超时,请问为什么?有什么改进方法吗?
set fong_hc=1
from
fong_hc a
join
fong_temphc b on a.fong_hc=b.qcid and b.ybbj=1
set fong_hc.ybbj=1
from
fong_hc a
join
fong_temphc b on a.fong_hc=b.qcid and b.ybbj=1
set fong_hc.ybbj=1
from
fong_hc a
join
fong_temphc b on a.qcid=b.qcid and b.ybbj=1请问为什么要这样修改还有一个问题,这个语句很多情况下都可以执行,现在fong_temphc只有一行记录,却无法完成,现在改了,执行了3分钟还没完
而且,我查过b.qcid在a表中确实存在
Set dbo.fong_hc.ybbj = 1
from (select QCID,ybbj from dbo.fong_temphc) as tb
where dbo.fong_hc.qcid=tb.qcid and tb.ybbj=1----
LZ这句是先子查询后再修改,而风的这句是先关联在修改,
效率上明显高.update fong_hc
set fong_hc.ybbj=1
from
fong_hc a
join
fong_temphc b on a.qcid=b.qcid and b.ybbj=1
Set A.ybbj = 1
From dbo.fong_hc A
Inner Join fong_temphc B On B.qcid=A.qcid And B.ybbj=1
Try下面语句:一定要先建好索引
Update A
Set A.ybbj = 1
From fong_temphc B
Inner Join dbo.fong_hc A On B.qcid=A.qcid
Where B.ybbj=1
执行十分钟之后依然没有结果
奇怪的是,出错的时候总是fong_temphc只有一条记录
Set dbo.fong_hc.ybbj = 1
from (select QCID,ybbj from dbo.fong_temphc) as tb
where dbo.fong_hc.qcid=tb.qcid and tb.ybbj=1先执行tb.ybbj=1呢?update dbo.fong_hc
Set dbo.fong_hc.ybbj = 1
from (select QCID,ybbj from dbo.fong_temphc where ybbj=1) as tb
where dbo.fong_hc.qcid=tb.qcid
1.select QCID,ybbj into #tb from dbo.fong_temphc where ybbj=1
2.update dbo.fong_hc
set dbo.fong_hc.ybbj = 1
from #tb as tb, dbo.fong_hc as f
where f.qcid=tb.qcid
但是这依然不是能解决问题
现在出错的地方表dbo.fong_temphc只有一条记录
QCID=c88fd3d4-9724-4f29-8abc-bbd88750fd26
ybbj=1而且,dbo.fong_hc中存在这样一条记录
QCID=c88fd3d4-9724-4f29-8abc-bbd88750fd26
...
ybbj=0
dbo.fong_hc有66万多记录,一定要为字段qcid建好索引,
否则Update时,执行表扫描,性能将大大折扣,
建议查看一下计划,或者用Sql Server Profiler跟踪一下执行脚本,然后分析
一下最耗时的点在什么地方。
一个连接就表示一个用户,是吗?
我在程序中用ado连接的,一个静态Recordset和Command应该不会冲突吧?