萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> access教程 >> access基礎教程 >> Access教程:如何提高ACCESS查詢性能

Access教程:如何提高ACCESS查詢性能

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;
copyright © 萬盛學電腦網 all rights reserved