批量数据修改

我要修改一个表中一个字段的内容。这个表包含2万多条记录。我用ASP写了以下程序。但是由于数据量太大,IIS服务器运行经常超时,每次运行也就能修改20几条。

程序如下:

 1   
 2set conn = server.CreateObject ("ADODB.Connection")   
 3conn.Open "DSN=MYDBODBC;Uid=sa;Pwd=;"   
 4  
 5set rs=server.CreateObject("ADODB.RecordSet")   
 6set rst=server.CreateObject("ADODB.RecordSet")   
 7sSql="SELECT SN,ModelName FROM warranty WHERE LEN(ModelName)< 8"   
 8rs.Open sSql,Conn,3,2   
 9while not rs.eof   
10  
11sSql="select SN,ModelName from tempin"   
12rst.open sSql,Conn   
13do while not rst.eof   
14if rs("SN")= rst("SN") then   
15rs("ModelName")=rst("ModelName")   
16sSql = "delete from tempin where SN='" & rst("SN") & "'"   
17conn.Execute sSql   
18exit do   
19end if   
20rst.movenext   
21loop   
22  
23rst.close   
24rs.movenext   
25wend   
26rs.close   
27conn.Close   
28set Conn=nothing   
29response.write "数据库执行完毕"   
30  

请问我应该怎么办?
---------------------------------------------------------------

更新保存:
dim zxhong
for i=1 to count
zxhong=request.form( "zxhong "&i)
sql= " update test set zxhong= "&zxhong& " where id=' "&id
response.write sql
conn.execute sql
next
---------------------------------------------------------------

使用存储过程,我做过实验,存储过程的效率比语句的效率高出很多的。
---------------------------------------------------------------

只有用存储过程。

或者用sqlerver的内部语句,但是过程要烦一点。

我曾经用过同样的方法来试过asp在网页中的执行效率太低了。。。

或者你也可以把settimeout 放大一点比如:3个小时什么的。。。。
另外 更新语句尽量用sql语句,不要用ado来执行。效率可能更高一点
---------------------------------------------------------------

update warranty set warranty.modelName = tempin.modelName from warranty,tempin where warranty.SN = tempin.SN and LEN(ModelName)< 8

Published At
Categories with Web编程
Tagged with
comments powered by Disqus