declare c1 cursor for select socode ,actname from t_sa_order where Entrusttype is null open c1 fetch next from c1 into @socode,@actname while(@@fetch_status=0)begin select top 1 @EntrustCode=Entrustcode,@Entrusttype=Entrusttype from t_sa_Entrust where @actname like '% '+actname+ '% ' if (@EntrustCode is not null) begin update t_sa_order set EntrustCode=@EntrustCode, Entrusttype = 'a ' where socode =@socode set @EntrustCode = null end fetch next from c1 into @socode,@actname end close c1 deallocate c1 上面的一段代码,其中t_sa_order 中的一个汉字串 ,想和t_sa_Entrust中的汉字串比较。 有几个字相等即表示相同。 t_sa_order 中有2W条数据, t_sa_Entrust 中有8k条数据。 按上面的过程执行起来特别慢,求高手优化! 或者给优化建议!
这个问题第1个回答:
怎么没有人回复一下呢?太幼稚了?
这个问题第2个回答:
无法从你的代码能知道你的要求,能否给个简单的数据。 这也方便大家帮你解决问题。
这个问题第3个回答:
比如说 “欢乐中国行第3CD-002” 和“欢乐中国行”进行匹配,我就可以认为他们是一样的数据。 “欢乐中国行第3CD-002” 和“快乐大本营”进行匹配,我就认为他们是不同的。
这个问题第4个回答:
update a set EntrustCode=B.EntrustCode, Entrusttype = 'a ' from t_sa_order A, t_sa_Entrust B where A.Entrustcode=B.Entrustcode and A.actname like '% '+B.actname+ '% '
这个问题第5个回答:
不是这个意思,因为汉字的比较很慢,我2W多条A表数据,和8k条B表数据比较的话,竟然需要多半个小时。。。。。
这个问题第6个回答:
用游标比较当然慢啦。
这个问题第7个回答:
如果批处理的话,服务器会很钝!!影响正常工作了,就!
这个问题第8个回答:
up
这个问题第9个回答:
不明白你说的批处理是什么意思,你用游标的话每个都比较效率肯定是个大问题 2w x 8k 的比较量 涉及到like的时候不会用到索引,也会降低效率 如果你只是全匹配汉字,那再两个表中分别增加一个字段,这个字段存储汉字的部分,建立索引,联合查询更新就行了。
这个问题第10个回答:
SQL Server2000 索引结构及其使用 http://blog.csdn.net/senaku/archive/2007/08/14/1743023.aspx 楼主看看,自然就明白了.
|