• 主页

# 我如何提高数据库数据访问效率？马上结分！

htjuw 2002-02-21 10:17:24

m1,m2,m3,m4
s1,s2,s3,s4
e1,e2,e3,e4

...全文
28 点赞 收藏 8

8 条回复

htjuw 2002-02-21

riyueming 2002-02-21
up

dbcontrols 2002-02-21

If Asc(a1) < 0 Then
t1 = Left(a1, 1)
If Asc(t1) < Asc("啊") Then
GetPY = "0"
Exit Function
End If
If Asc(t1) >= Asc("啊") And Asc(t1) < Asc("芭") Then
GetPY = "A"
Exit Function
End If
If Asc(t1) >= Asc("芭") And Asc(t1) < Asc("擦") Then
GetPY = "B"
Exit Function
End If
If Asc(t1) >= Asc("擦") And Asc(t1) < Asc("搭") Then
GetPY = "C"
Exit Function
End If
If Asc(t1) >= Asc("搭") And Asc(t1) < Asc("蛾") Then
GetPY = "D"
Exit Function
End If
If Asc(t1) >= Asc("蛾") And Asc(t1) < Asc("发") Then
GetPY = "E"
Exit Function
End If
If Asc(t1) >= Asc("发") And Asc(t1) < Asc("噶") Then
GetPY = "F"
Exit Function
End If
If Asc(t1) >= Asc("噶") And Asc(t1) < Asc("哈") Then
GetPY = "G"
Exit Function
End If
If Asc(t1) >= Asc("哈") And Asc(t1) < Asc("击") Then
GetPY = "H"
Exit Function
End If
If Asc(t1) >= Asc("击") And Asc(t1) < Asc("喀") Then
GetPY = "J"
Exit Function
End If
If Asc(t1) >= Asc("喀") And Asc(t1) < Asc("垃") Then
GetPY = "K"
Exit Function
End If
If Asc(t1) >= Asc("垃") And Asc(t1) < Asc("妈") Then
GetPY = "L"
Exit Function
End If
If Asc(t1) >= Asc("妈") And Asc(t1) < Asc("拿") Then
GetPY = "M"
Exit Function
End If
If Asc(t1) >= Asc("拿") And Asc(t1) < Asc("哦") Then
GetPY = "N"
Exit Function
End If
If Asc(t1) >= Asc("哦") And Asc(t1) < Asc("啪") Then
GetPY = "O"
Exit Function
End If
If Asc(t1) >= Asc("啪") And Asc(t1) < Asc("期") Then
GetPY = "P"
Exit Function
End If
If Asc(t1) >= Asc("期") And Asc(t1) < Asc("然") Then
GetPY = "Q"
Exit Function
End If
If Asc(t1) >= Asc("然") And Asc(t1) < Asc("撒") Then
GetPY = "R"
Exit Function
End If
If Asc(t1) >= Asc("撒") And Asc(t1) < Asc("塌") Then
GetPY = "S"
Exit Function
End If
If Asc(t1) >= Asc("塌") And Asc(t1) < Asc("挖") Then
GetPY = "T"
Exit Function
End If
If Asc(t1) >= Asc("挖") And Asc(t1) < Asc("昔") Then
GetPY = "W"
Exit Function
End If
If Asc(t1) >= Asc("昔") And Asc(t1) < Asc("压") Then
GetPY = "X"
Exit Function
End If
If Asc(t1) >= Asc("压") And Asc(t1) < Asc("匝") Then
GetPY = "Y"
Exit Function
End If
If Asc(t1) >= Asc("匝") Then
GetPY = "Z"
Exit Function
End If
Else
If UCase(a1) <= "Z" And UCase(a1) >= "A" Then
GetPY = UCase(Left(a1, 1))
Else
GetPY = "0"
End If
End If
End Function

valhallen 2002-02-21

feihong0233 2002-02-21
SELECT [地区字段] FROM [表] WHERE (m1 BETWEEN s1 AND e1) AND (m2 BETWEEN s2 AND e2) AND (m3 BETWEEN s3 AND e3) AND (m4 BETWEEN s4 AND e4)

dbcontrols 2002-02-21

JET数据库的查询优化是有代价的，随着数据库的不断扩大，优化将不再起作用。压缩数据库会改变数据库的状态，并重新优化所有查询。同时，随着数据库的增大，会产生很多碎片。而压缩数据库可以把一个表中的数据数据写到硬盘中连续的页里，提高了顺序搜索的速度。

DBEngine.CompactDatabase “C:\VB\BIBLIO.MDB”, “C:\VB\BIBLIO2.MDB”
Kill “C:\VB\BIBLIO.BAK” Name “C:\VB\BIBLIO.MDB” As “C:\VB\BIBLIO.BAK”
Name “C:\VB\BIBLIO2.MDB” As “C:\VB\BIBLIO.MDB”

Dim DB As Database
Dim RS As RecordSet
Set DB = DBEngine.Workspaces(0).Opendatabase(“Biblio.MDB”)
DB.CreateQueryDef(“Query1”, _
“SELECT IIF(Au_ID=1,’Hello’,’Goodbye’) AS X FROM Authors”)
Set RS = DB.OpenRecordSet(“SELECT * FROM Query1 WHERE X=’Hello’”)

Set RS = DB.OpenRecordSet(“SELECT * FROM Authors WHERE Au_ID=1”)

DB.CreateQueryDef(“Query1”, _
“SELECT IIF(Au_ID=1,’Hello’,’Goodbye’) AS X, Au_ID, FROM Authors”)
Set RS = DB.OpenRecordSet(“SELECT * FROM Query1 WHERE Au_ID=1”)

SELECT Cust.CustID,
FIRST(Cust.CustName) AS CustName,
SUM(Ord.Price) AS Total
FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID
GROUP BY Cust.CustID

SELECT Ord.CustID,
FIRST(Cust.CustName) AS CustName,
SUM(Ord.Price) AS Total
FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID
GROUP BY Ord.CustID

SQL语句中分组（GROUP BY）的字段越多，执行查询的时间越长。在GROUP BY子句中尽量用aggregate函数来减少字段的数量。

GROUP BY As Few Fields As Possible
SELECT Cust.CustID,
Cust.CustName,
Cust.Phone,
SUM(Ord.Price) AS Total
FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID
GROUP BY Cust.CustID, Cust.CustName, Cust.Phone

SELECT Ord.CustID,
FIRST(Cust.CustName) AS CustName,
FIRST(Cust.Phone) AS Phone,
SUM(Ord.Price) AS Total
FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID
GROUP BY Ord.CustID

SELECT Ord.CustID,
FIRST(Cust.CustName) AS CustName,
FIRST(Cust.Phone) AS Phone,
SUM(Ord.Price) AS Total
FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID
GROUP BY Ord.CustID

SELECT CustID, SUM(Price) AS Total
FROM Ord
GROUP BY CustID

SELECT Query1.CustID, Cust.CustName, Cust.Phone, Query1.Total
FROM Cust INNER JOIN Ord ON Cust.CustID = Ord.CustID

Microsoft Jet数据库引擎有特别的优化方法，它在使用COUNT(*)要比用COUNT([Column Name])快得多。

Count(*) 计算所有的行。
Count([Column Name])计算所有Column Name非空的行。

Like "Smith"
Like "Sm*"

Like "*sen"
Like "*sen*"

SELECT Customers.*
FROM Customers
WHERE Customers.[Customer ID]
NOT IN (SELECT [Customer ID] FROM Orders);

SELECT Customers.*
FROM Customers LEFT JOIN Orders
ON Customers.[Customer ID] = Orders.[Customer ID]
WHERE ((Orders.[Customer ID] Is Null));

valhallen 2002-02-21

dbcontrols 2002-02-21
IFF

1181

VB 数据库(包含打印，安装，报表)