會員登錄 - 用戶注冊 - 網(wǎng)站地圖 Office中國(office-cn.net),專業(yè)Office論壇
當(dāng)前位置:主頁 > 技巧 > Access技巧 > 數(shù)據(jù)表 > 正文

ACCESS的真假:三、往一個表中插入10萬條記錄的速度小于插入1萬

時間:2009-09-12 10:04 來源:blog.csdn.net 作者:ACMAIN_C… 閱讀:
正 文:

下面這個貼子中討論了很多access中的一些猜想假設(shè)。

access或其它數(shù)據(jù)庫操作效率問題.歡迎討論

 

引用 28 樓 wwwwb 的回復(fù)::
比如插入10萬條記錄,速度 <插入1萬條記錄;
面對這個問題,第一想法上,在一個mdb文件插入過多的記錄,自然會導(dǎo)致MDB文件增大,需要不停地向操作系統(tǒng)申請磁盤空間的分配。因故會導(dǎo)致速度慢。但再仔細(xì)一想好象也沒什么道理,畢竟加10000條也要申請10000條記錄的空間,速度上應(yīng)該沒什么影響。畢竟access中又不會去用什么redo / undo log.

于是便做了個簡單的測試如下以對這個猜想證實(shí)。

新建空的 t.mdb 文件,創(chuàng)建表 table1 (id int primary key,cname varchar(10)

然后新建 模塊,內(nèi)容如下。

view plaincopy to clipboardprint?
Option Compare Database  
Option Explicit  
 
 
Public Sub t1(nRowCnt As Long)  
    Dim i As Long 
    Dim conn As ADODB.Connection  
    Set conn = CurrentProject.Connection  
      
    For i = 1 To nRowCnt  
        conn.Execute "insert into table1(id,cname) values(" & i & ",'" & i & "')" 
    Next i  
      
      
End Sub 
 
 
Public Sub t()  
    CurrentProject.Connection.Execute "delete from table1" 
      
    Debug.Print "t10000 start.", Now  
    Call t1(10000)  
    Debug.Print "t10000 end  .", Now  
      
    CurrentProject.Connection.Execute "delete from table1" 
      
    Debug.Print "t100000 start.", Now  
    Call t1(100000)  
    Debug.Print "t100000 end  .", Now  
      
End Sub 
Option Compare Database
Option Explicit


Public Sub t1(nRowCnt As Long)
    Dim i As Long
    Dim conn As ADODB.Connection
    Set conn = CurrentProject.Connection
   
    For i = 1 To nRowCnt
        conn.Execute "insert into table1(id,cname) values(" & i & ",'" & i & "')"
    Next i
   
   
End Sub


Public Sub t()
    CurrentProject.Connection.Execute "delete from table1"
   
    Debug.Print "t10000 start.", Now
    Call t1(10000)
    Debug.Print "t10000 end  .", Now
   
    CurrentProject.Connection.Execute "delete from table1"
   
    Debug.Print "t100000 start.", Now
    Call t1(100000)
    Debug.Print "t100000 end  .", Now
   
End Sub

運(yùn)行 t() 結(jié)果如下:
t10000 start.  5/14/2009 7:53:10 PM
t10000 end  .  5/14/2009 7:53:29 PM
t100000 start.  5/14/2009 7:53:29 PM
t100000 end  .  5/14/2009 7:56:06 PM


t10000 .  19s 
t100000 .  157 s

試驗(yàn)結(jié)論:

插入10萬條的總時間顯然比插入1萬長(157s>19s),但速度顯然快(157/100000<19/10000)

看來實(shí)踐是檢驗(yàn)的唯一標(biāo)準(zhǔn)啊。



(責(zé)任編輯:admin)

頂一下
(1)
100%
踩一下
(0)
0%
發(fā)表評論
請自覺遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴(yán)禁發(fā)布色情、暴力、反動的言論。
評價: