然後新建 模塊,內容如下。
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
運行 t() 結果如下:
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
試驗結論:
插入10萬條的總時間顯然比插入1萬長(157s>19s),但速度顯然快(157/100000<19/10000)
看來實踐是檢驗的唯一標准啊。