Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-查询/SQL语句

[access查询]提高access查询性能的方法

时 间:2007-05-24 00:00:00
作 者:UMVsoft整理   ID:8  城市:上海  QQ:2851379730点击这里给张志发消息
摘 要:如何提高ACCESS的查询性能
正 文:

正    文:当我们为了提高access查询性能时,可通过以下方法来实现.

一、代码部分

要提高查询性能, 请尝试下列操作:

压缩数据库

压缩数据库时, 能够加速查询。 压缩数据库, 时记录对表是重组以便记录位于相邻数据库页, QUALIFIER 是表主键。 因为只有最小数量的数据库页现在有要读取以检索记录, 如果想这改善了顺序扫描表中的记录性能。 压缩数据库, 后运行每个查询以编译查询以便每个查询将现在具有表更新统计。
索引字段

索引是用于设置查询字段和索引字段条件两边联接的任何字段。 或者, 创建这些字段间关系。 外键上如果一个不存在当您创建关系, Jet 数据库引擎创建索引。 否则, Jet 数据库引擎使用现有索引。

注意 : 则Jet 数据库引擎自动优化如果 Access 表很小并且如果联接字段已经索引联接查询该查询联接硬盘上 Access 表和 ODBC 服务器表。 可以通过从服务器请求需要记录此时, Access 提高性能。 请确保根据联接字段, 从不同来源加入表索引。
选择小是适当数据类型

表, 中定义字段时选择小数据类型是适合字段中数据。 Also, make sure that fields that you plan to use in joins have the same data types or compatible data types, such as Autonumber and Number (if the FieldSize property is set to Long Integer).
仅添加字段, 必须

当您创建查询, 只添加字段, 必须。 用于设置条件, 字段中单击以清除 显示 复选框如果您不希望以显示这些字段。
SQL 语句另存为查询

If the RecordSource property for a form or for report is set to an SQL statement, save the SQL statement as a query and then set the RecordSource property to the name of the query.
避免计算字段

避免查询中计算字段。 如果将一个包含计算字段到另一个查询, 查询可能会影响性能顶级查询中计算字段中表达式。 在以下示例, 用于查询 Q 2 用作查询 Q 1: 输入
Q 1: SELECT IIF([MyColumn]="Yes","Order Confirmed","Order Not Confirmed") AS X FROM MyTable;
Q 2: SELECT * FROM Q 1 WHERE X = " 订单已确认 " ;
因为 Q 1 中 IIF 表达式能优化, Q 2 也能优化。 如果在子查询, 嵌套表达式能优化, 能优化所有查询。

一个替代方法来构造查询是如下:
Q 1: SELECT * FROM MyTable WHERE MyColumn = " 是 " ;
如果表达式所需输出, 中尝试置于表达式控件在窗体或报表上。 For example, you can change the previous query to a parameter query that prompts for the value of MyColumn, and then base a form or a report on the query. On the form or on the report, you can then add a calculated control that displays "Hello" or "Goodbye," depending on the value that is in MyColumn.

构造查询如下:
PARAMETERS [ 要看到确认订单, 请输入 Yes。 要查看确认订单, 输入 ] " 否 "。 文本;
SELECT *
FROM MyTable
WHERE MyColumn = [ 要看到确认订单, 请输入 Yes。 要查看确认, 订单输入 ] " 否 "。;
请在窗体或报表, 上计算控件中键入:
= IIF([MyColumn]="yes","order confirmed","order not confirmed")
指定分组依据

按, 联接字段中值分组记录时为正在作为域, 您将汇总上 (计算聚合) 相同的表字段指定 GroupBy。 For example, in the Northwind.mdb sample database, if you create a query that totals the Quantity field in the Order Details table and then groups by OrderID, you can specify Group By for the OrderID field in the Order Details table. If you specify Group By for the OrderID field in the Orders table, Access must join all the records first and the



Access软件网QQ交流群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助