發(fā)布時(shí)間:2015/8/14 8:01:25 關(guān)注:1638
1 明確查詢(xún)的字段名稱(chēng)
2 使用rs(0)比rs(“name”)更快
3 使用記錄集rs值前,將其賦值給變量
4 [TEST] 現有10W條數據,Access數據庫保存
通過(guò)正常提取 | 通過(guò)存儲過(guò)程提取| 使用GetRows()方法提?。?
1 明確查詢(xún)的字段名稱(chēng)
Select * from [data_table]
即從數據庫data_table種抽取所有字段的記錄值
Select * 語(yǔ)句的執行效率非常低,因為執行這樣的語(yǔ)句時(shí)執行了兩次查詢(xún), 先查詢(xún)系統表來(lái)確定名稱(chēng)和數據類(lèi)型.然后再查數據
所以精良減少使用select * 語(yǔ)句,而使用明確的字段名稱(chēng),如:
Select name,pwd from [data_table]
2 使用rs(0)比rs(“name”)更快
記錄集rs()里面可以寫(xiě)字段名,或字段索引號.比如
Rs(0)對應rs(“name”)
Rs(1)對應rs(“pwd”)
已證明用索引數訪(fǎng)問(wèn)記錄集要比字段名快出幾倍,按字符串查詢(xún)要比按整數查詢(xún)花去的更多的時(shí)間和系統資源
3 使用記錄集rs值前,將其賦值給變量
<%
Set rs=conn.execute(“select cname,cpwd from [data_table] where id=1”)
If not rs.eof then
Do while not rs.eof
Cname=rs(0) 將rs賦值給變量
Cpwd=rs(1)
….
Rs.moveNext
Loop
End if
%>
4 [TEST] 現有10W條數據,Access數據庫保存。
A.通過(guò)正常提?。?/strong>
<%
Set rs=server.createObject(“adodb.recordSet”)
Rs.open “select * from people order by id desc”,cn,1,1
Do while not rs.eof
Response.write rs(“id”)&” | ”
Rs.moveNext
loop
%>
耗時(shí)3,250.000毫秒 3秒
B. 通過(guò)存儲過(guò)程提?。?/strong>
<%
Set cn=server.createObject(“adodb.connection”)
Cn.open “driver={microsoft access driver (*.mdb)};DBQ=”&server.mapPath(“db2.mdb”)
Set cmd=server.createObject(“adodb.command”)
cmd.activeConnection=cn
cmd.commandText=”select * from people order by id desc”
set rs=cmd.execute
do while not rs.eof
response.write rs(“id”)&” | ”
rs.moveNext
loop
%>
耗時(shí) 2,187.500毫秒 2秒
C.使用GetRows()方法提?。?/u>
<%
Set cn=server.createObject(“adodb.connection”)
Set cmd=server.createObject(“adodb.command”)
Cn.open “driver={microsoft access driver (*.mdb)};DBQ=”&server.mapPath(“db2.mdb”)
cmd.activeConnection=cn
cmd.commandText=”select * from people order by id desc”
set rs=cmd.execute
rsArray=rs.getRows() 將記錄集數據存入一個(gè)數組, 該數組默認為二維數組
for i=0 to uBound(rsArray,2) Ubound(array,num) 其中num意指數組維數, 默認不填為一維, 2等于二維
response.write rsArray(0,i)&” | ”
next
%>
耗時(shí):187.500毫秒 0.2秒
rsArray(a,b)
a表示存入該數組記錄集的字段號 b表示存入該數組記錄集的條數
如下表:
id | uname | upwd |
RsArray(0,0) | RsArray(1,0) | RsArray(2,0) |
RsArray(0,1) | RsArray(1,1) | RsArray(2,1) |
RsArray(0,2) | RsArray(1,2) | RsArray(2,2) |
地址:山東省濰坊奎文區新華路樂(lè )川街華誼大廈三樓
網(wǎng)址:http://m.hwj688.cn/ 垂詢(xún)電話(huà):
網(wǎng)站備案:魯ICP備14027302號-5
copyright© 濰坊華邦網(wǎng)絡(luò )有限公司2011-2025