SQL Server Dmax速度

时间:2014-10-27 19:03:44

标签: sql-server vba ms-access sql-server-2012 ms-access-2010

我有一个连接到指定服务器/数据库的访问ADP

我需要在同一台服务器上从另一个数据库获取日期,但速度非常慢 如何在没有索引的情况下更快地完成此操作?

测试代码:

Option Compare Database
Option Explicit

Sub testing(tablename As String)
Dim q
Dim z As Date
Dim rs
Dim cmd

q = Timer
z = DMax("created", tablename)
Debug.Print "Dmax: "; Timer - q; " Secs"

q = Timer
Set cmd = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")

cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "select max(created) from " & tablename
cmd.CommandTimeout = 0
Set rs = cmd.Execute

z = rs.Fields(0).value
Debug.Print "SQL: "; Timer - q; " Secs"

q = Timer
Set cmd = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")

cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "select top 1 created from " & tablename & _
                  " order by created desc"
cmd.CommandTimeout = 0
Set rs = cmd.Execute

z = rs.Fields(0).value
Debug.Print "SQ2L: "; Timer - q; " Secs"
End Sub

结果:

  

Dmax:102.4297秒   SQL:59.87109秒   SQ2L:74.80078秒

0 个答案:

没有答案