有2个表A,B,两个表都有30000条记录,根据户号比较,如果相同户号的就用B表的数据update A表的数据,如果B的户号在A没有则insert A表
语句如下
insert into A(x1,x2,x3) select x1,x2,x3 from B where A.x1 not in (select x1 from B)
update A set a.x2=b.x2,a.x3=b.x3 from a,b where a.x1=b.x1
在查询分析器中能够执行,第一条要7分,第而条要23分
在程序中执行就说超时 TimeOut expried 有什么好办法能解决啊
语句如下
insert into A(x1,x2,x3) select x1,x2,x3 from B where A.x1 not in (select x1 from B)
update A set a.x2=b.x2,a.x3=b.x3 from a,b where a.x1=b.x1
在查询分析器中能够执行,第一条要7分,第而条要23分
在程序中执行就说超时 TimeOut expried 有什么好办法能解决啊
解决方案 »
- webbrowser弹出网页的问题
- 我这个菜鸟实在是不会用 append 来增加数据列,还请各种高手相救了
- 这个系统怎么做?求思路
- 羽毛球问题:我有一个很要好的朋友
- 如何判断一个记录集对象是否关闭!
- Adodc控件的fefresh属性和update属性有什么区别呢?
- 如何将两个BMP(黑白)文件连接成一个大的BMP文件
- 如何使报表控件(ActiveReport2.0)只显示而不打印?
- 请问,VB里把一个数字串(如 "34567.34")转换成数字,有没有函数可以做到这一点?????
- 请问vb中如何进行位操作?如移位,位异或等
- 【求助】用VB做个备份程序...
- 请问 dedicate ip 是什么意思??
1. 两表的x1字段要建索引,加快速度。2. 连接的connectiontimeout和commandtimeout属性都设为0。3. 语句执行的顺序不要随便,先update,再insert才正确。4. 语句优化: update A set x2=b.x2,x3=b.x3 from a join b on a.x1=b.x1 insert into A (x1,x2,x3)
select x1,x2,x3
from B left join A on a.x1=b.x1 and a.x1 is null
另外插入后更新的话由于记录增多会增加筛选时间,故先更新在插入会合适些
如果是vb中运行,建议你改成存储过程调用,另外为了不超时,可以将超时设定为0(永不超时)update A set x2=b.x2,x3=b.x3 from a,b where a.x1=b.x1insert into A (x1,x2,x3)
select x1,x2,x3
from b
where not exists(select 1 from a where a.x1=b.x1)或 insert into A(x1,x2,x3) select x1,x2,x3 from B where A.x1 not in (select distinct x1 from B)