The information in this article applies to:
SUMMARY
This article explains how to avoid some of the most common errors with
Microsoft Visual Basic version 3.0 database programming. Use these tips to
avoid unnecessary bottlenecks when executing queries on your databases.
MORE INFORMATIONAvoid Redundant TablesFrequently, a second copy of an existing table is not joined to anything. This slows down the query process and causes unwanted records to appear in query results.Avoid Expressions in Query OutputBy placing expressions in the output column of a query, you may cause optimization problems. For example, consider a situation where one query is used as input to another query as in this example:
This causes an optimization problem because the Microsoft Access database engine cannot optimize the IIF() expression, so it cannot optimize Query2. Sometimes expressions get buried so far down in a query tree, that you may not even realize they're there. Here's a more optimal way to write this query:
Place Group By Column in the Same Table as AggregateWhen joining two tables, make sure the Group By column (Column1) and the column in the aggregate (Sum, Count, and so on) both come from the same table.Group By as Few Columns as PossibleWhen creating queries that display totals using the Microsoft Access database engine, place as few columns as possible in the Group By clause. The more columns the query has to group by, the longer it will take.Place the Group By Before the JoinIf possible, use the Group By with a single table, and then join that table to another table rather than joining the tables and doing the Group By in the same query. Here are two examples:Example One:
Example Two:
Index the Join Column from Both TablesWhen joining tables, index the fields on both sides of a join. This can speed query execution by allowing more sophisticated join strategies such as Index Join and Index-Merge Join.Index Fields as Much as PossibleWhen in doubt, index. If the frequency of updating the database is low, place an index on all columns that will be used as join columns or that will be used in a restriction. With the Rushmore query optimization in the Microsoft Access version 2.0 database engine, the query engine is able to take advantage of multiple indexes on a single table.Use COUNT(*) Instead of COUNT([Column Name])To determine the number of records, use COUNT(*) rather than COUNT([Column Name]). COUNT(*) is executed much faster.These are just some tips to help you in the design and programming phase of creating your program. For information on optimizing your database design, please see the following article in the Microsoft Knowledge Base: Q100139 : INF: Database Normalization Basics Additional query words: 3.00
Keywords : |
Last Reviewed: May 11, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |