请各位大侠帮忙看看,

qingyun67 2005-05-10 11:22:30
INSERT INTO table1(tab1_code,date,addDtime,Adder) select tab2_code,'2005-5-8',getdate(),'123456' from table2 where tab2_code not in (select tab1_code from table1
where date='2005-5-8' ) and tab2_code2='001'
vb+sqlserver2000

这个是我写的插入语句(批量插入,每次插入300左右的数据),date,tab1_code,CancCode(删除标记)做联合主建,
tab1_code从table2中的字段tab2_code得到,
表中的数据大概到6、7万的时候执行插入就非常慢,请大家帮忙看看,是什么原因呢?

表中的数据多,但是要插入和查出的不多,数据库中的数据如果10万以下的时候,也就是比较少的时候速度正常,能够插入和查出,可是数据表中的数据在10几万的时候就非常慢了,
...全文
92 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
junhualee 2005-05-11
  • 打赏
  • 举报
回复
INSERT INTO table1(tab1_code,date,addDtime,Adder)
select T.tab2_code,'2005-5-8',getdate(),'123456' from (select tab2_code ,date from table2 where tab2_code2='001')T where T.date='2005-5-8'
freddy2003 2005-05-11
  • 打赏
  • 举报
回复
安装server sp4。sp4对in有优化
venket 2005-05-11
  • 打赏
  • 举报
回复
一加索引
二最好少用in
因为他会影响速度
freddy2003 2005-05-11
  • 打赏
  • 举报
回复
tab2_code与tab2_code2与date加索引
qingyun67 2005-05-11
  • 打赏
  • 举报
回复
INSERT INTO table1(tab1_code,date,addDtime,Adder) select tab2_code,'2005-5-8',getdate(),'123456' from table2 where tab2_code not in (select tab1_code from table1
where date='2005-5-8' ) and tab2_code2='001'

table2的表结构:
tab2_code(主建) tab2_code2
001001 001
001002 001
001003 001
002001 002
……………………
table1的表结构
tab1_code, date, CancCode, addDtime, Adder
001001 2005-5-1 2005-5-1 1
001002 2005-5-1 2005-5-1 1

如果在table1中当date='2005-5-8' 时不存在tab1_code 相对应tab2_code2=‘001’的记录时
向表table1中追加当tab2_code2=‘001’时对应的table2的记录

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧