======================================================================== 
                        Microsoft Access  
                   Tables and Database Design  
                  Common Questions and Answers         November 11, 1993 
======================================================================== 
 
The following are common questions and answers.  This list is updated as  
needed.  If you have any suggestions or additions to this list, please  
mail Michael Patten [MSFT] 71742,1175.  Thank you. 
------------------------------------------------------------------------ 
 
QUESTION: 
========= 
Using the Database Analyzer (Analyzer.MDA), is it possible to extract 
the description field from tables? 
 
ANSWER: 
======= 
Currently, Access provides no method to extract the description field 
from tables.  Product management is aware of this issue.  One suggestion 
is to create a new from using the Wizards based on the table with the 
descriptions.  By default, the control property StatusText on a form 
will contain the information from the description field.  Now, you can 
use Analyzer.MDA to extract the information from the StatusText field.  
 
QUESTION: 
========= 
I have noticed several new tables that all begin with Msys.  I have 
tried to delete them but cannot.  Where did these tables come from and 
how can I remove them. 
 
ANSWER: 
======= 
DO NOT DELETE these tables.   These tables are Access internal database 
tables.  They contain important information about your database.  To 
hide these tables from the database container, select View/Options.  Set 
Show System Objects to no. 
 
QUESTION: 
========= 
What do files with the LDB extension do?  Can I delete them? 
 
ANSWER: 
======= 
These files are used to control page locking in Access tables.  The file 
is automatically created when the MDB file is opened.  You can safely 
delete this file only when the MDB file is not opened by ANY user.  
 
QUESTION: 
========= 
How do Access indexes work?  What are the best indexes to use?  What 
fields should I index? 
 
ANSWER: 
======= 
This answer is divided into three parts, as follows: 
  
1. General Information (storage of Microsoft Access tables and indexes) 
2. Rules and Limitations (when indexes can be used) 
3. Examples (example queries and their associated indexes) 
  
GENERAL INFORMATION  
=================== 
  
Table Storage 
-------------- 
Microsoft Access stores information in 2K pages. Each table is made up 
of a 2K header page and as many 2K data pages as are needed to store 
the data in the table. Records are placed in a table in the order in 
which they are entered. 
  
Index Storage 
------------- 
Indexes are also stored in 2K pages. Each index consists of a header 
page and leaf pages. Leaf pages contain a key generated from the value 
of the field that is indexed and a pointer to the 2K page on which 
that record resides. 
  
Table Statistics 
---------------- 
Microsoft Access maintains information on the approximate number of 
records in each table and the number of data pages on which that table 
resides. This information is used to determine the most effective 
way to locate or retrieve data in a table. 
  
Query Optimization 
------------------ 
The process of determining the fastest method to access data is called 
query optimization. Records in a single table can be retrieved using a 
base table scan or an indexed search, as described below: 
  
Base Table Scan: 
A base table scan involves reading each record in the table and 
determining whether or not it matches the criteria.  
 
The drawback to this method is that each 2K data page must be loaded 
into memory and then each record examined. However, when the query 
includes most of the data in the table, or at least one record each 
from a majority of the data pages, a base table scan can be faster 
than an indexed search. 
  
Indexed Search: 
When an index is used, Microsoft Access searches the index for the 
first occurrence of the specified data and then loads into memory the 
2K data page that contains the record to which the index points.  
 
The drawback to this method is that both index pages and data pages 
must be loaded and read. In addition, an entire 2K page must be loaded 
into memory for each record reference by the index. However, when the 
criteria in the query restricts the results to a relatively small 
group of records, an indexed search may be much faster than a base 
table scan. 
 
RULES AND LIMITATIONS  
===================== 
Microsoft Access can use indexes to perform the following three tasks: 
  
1. To order records in a query. 
2. To select records that meet a specific criteria. That criteria must 
   be in one of the following formats: 
  
   a. = "value" 
   b. IN (valuelist) 
      or the equivalent: = "value OR = "value" OR = "value" 
   c. like "string*" 
   d. between 
   e. >=  >  <  <= 
  
3. To join two tables. 
  
Will An Index Always Be Used? 
----------------------------- 
The process of query optimization in Microsoft Access includes 
determining the fastest way to retrieve records from each table in the 
query. Each method available to Microsoft Access is considered and 
assigned a cost. That cost is based on several factors, including the 
following: 
  
 - How will the data be used? 
 - How many records total are there in the table? 
 - How large is the index? 
  
To understand why one method might be preferable over another, 
consider the following scenario: 
  
   The user wishes to view all records in the Orders table, sorted 
   by order date. There is an index on the Order Date field. There are 
   approximately 50 records on each 2K page in the Orders table.  
 
   The total time to read each page and then to sort the records using 
   a base table scan may actually be faster than using the index on 
   the Order Date field. To use the index, Microsoft Access must load 
   the first page of the index, load one 2K page for each record to 
   which the index points, then move to the next page in the index. 
 
   However, Microsoft Access has the ability to display the first 
   screen of data while completing the remainder of the query in the 
   background. For this form, Microsoft Access would likely use the 
   index to quickly retrieve the first 30 or so records, populate the 
   form so that the user can start working, and then retrieve the 
   remaining records as they are needed. 
  
EXAMPLES  
======== 
NOTE: Specific tables listed in the examples below can be found in the 
sample database NWIND.MDB.  
  
1. Q. How can I speed up a query that joins two tables? 
  
   A. By indexing the fields that are being joined in each of the                                                            
      tables. 
      This action allows Microsoft Access to quickly find all records 
      in the second table that match each primary key in the first 
      table. Microsoft Access then uses the statistics from each table 
      to determine the order in which to access them. For example, 
      if you are joining the Customers and Orders tables, verify that 
      the fields Customers.Customer ID and Orders.Customer ID are 
      indexed. 
  
2. Q. Example: SELECT [orders].* FROM orders ORDER BY [order id],  
      [customer id]; 
       
      If there is a primary key on the Order ID field, would it help to  
      have an index on the Customer ID field? 
  
   A. In this case, all records from the Orders table are being 
      retrieved; thus, it would not be beneficial to use the Primary 
      Key index. However, it would be helpful, if the query is used to 
      browse data, to have a compound index on the Order ID and 
      Customer ID fields. 
  
3. Q. Assuming a compound primary key on the Order ID, Customer ID, 
      Employee ID fields, would the following syntax be used in the 
      queries below? 
  
   A. 1) SELECT [orders].* FROM orders ORDER BY [order id], 
         [customer id], [employee ID]; 
  
         If you are browsing, yes, because the goal is to fill the 
         first screen quickly and an index allows you to do that. If you 
         are reporting, no, because the goal is to complete the report 
         quickly and sorting is generally faster than traversing an 
         entire index. 
  
      2) SELECT [orders].* FROM orders ORDER BY [order id], 
         [customer id]; 
  
         The answer to #1 applies to this query also. Microsoft Access 
         can use one of several keys of an index, as long as it is the 
         first part of the key that is used. 
  
      3) SELECT [orders].* FROM orders ORDER BY [customer id], 
         [employee ID]; 
  
         No, the index would not be used because the first field in 
         the index is not included. 
  
4. Q. Assuming a primary key on the Order ID field and an index on the 
      Customer ID and Order Date fields, would either be used to execute  
      the following queries? 
  
   A. 1) SELECT [orders].* FROM orders ORDER BY [order id] 
         WHERE [customer id] = "AAA"? 
  
         Assuming the restriction is fairly comprehensive, Microsoft 
         Access would use the Customer ID/Order Date index to solve 
         the restriction and then to sort. Using the index on the 
         Order ID field would be wasteful. It is possible to traverse 
         the entire Order ID index, looking at each row to evaluate 
         the restriction; however, this method is extremely slow, 
         unless many records meet the criteria (Customer ID = "AAA"). 
  
      2) SELECT [orders].* FROM orders ORDER BY [order id] WHERE 
         [customer id] = "AAA" And [Order Date] = "5/5/92". 
  
         The answer to #1 applies to this query also. Assuming you use 
         the Customer ID/Order Date index, Microsoft Access includes 
         the Order Date restriction in the index seek. 
  
      3) SELECT [orders].* FROM orders ORDER BY [order id] WHERE 
         [customer id] = "AAA" OR [Order Date] = "5/5/92" 
  
         Microsoft Access cannot use the index to solve the Order Date 
         restriction. 
  
      4) SELECT [orders].* FROM orders ORDER BY [order id] WHERE 
         [customer id] = "AAA" and [Order Date] LIKE "5/5/*" 
  
         The answer to #1 and #2 applies to this example as well. 
  
      5) SELECT [orders].* FROM orders ORDER BY [order id] WHERE 
         [customer id] = "AAA" Or [Order Date] like "5/5/*" 
  
         No, as in #3, the index cannot be used. 
  
5. Example: WHERE col1 > value1 and col1 < value2  
       
   Microsoft Access can use an index on col1 to retrieve only those 
   records that meet the specific criteria.  
  
6. Example: WHERE col1 < value and col2 > value 
      
   Microsoft Access must decide between the index on col1 or the index 
   on col2.      
 
QUESTION: 
=========   
I need to be able to print out the structure of my database. 
 
ANSWER:   
======= 
When you develop a new database or modify an existing one, you'll   
probably want detailed information about its structure. Microsoft  
Product Support Services provides an informal diagnostic tool for this  
purpose called the Database Analyzer. Using this tool, you can display  
or print tables listing the structural features of many of the objects  
in a database. For information on installing and using the Database  
Analyzer, read the ANALYZER.TXT file found in your Microsoft Access  
program directory. 
 
To add the Database Analyzer to your menu bar, add the following lines 
the MSACCESS.INI file in the Windows directory: 
 
   [Menu Add-ins] 
   &Database Analyzer==StartAnalyzer() 
 
   [Libraries] 
   Analyzer.MDA= 
 
Restart Microsoft Access. Now, Database Analyzer appears as a choice on  
the Help menu. When you choose Database Analyzer from the Help menu,  
Database Analyzer automatically starts. Now, it will appear as a menu  
option when you open any database. 
------------------------------------------------------------------------ 
 
QUESTION: 
========= 
When I try to create two relationships between the same two tables,  
Microsoft Access automatically delete the first relationship. 
 
ANSWER: 
======= 
This behavior is by design.  
 
Steps To Reproduce Behavior 
--------------------------- 
 
1. Create two tables that share a common field: 
 
   Table: Table1 
   ------------- 
      Field Name: Test [Primary key] 
      Date Type: Text 
 
   Table: Table2 
   ------------- 
      Field Name: Test 
      Date Type: Text 
 
2. From the Edit Menu choose Relationships and create a relationship  
between the Table1 and Table2 on the Test field with the Enforce  
Referential Integrity option checked. Choose Add. 
 
3. Create another relationship between the two tables. Choose Add.   
Creating the second relationship deletes the first relationship. 
------------------------------------------------------------------------ 
 
QUESTION: 
========= 
Can't Add Counter Columns to Tables w/ > 4 MB Data or receive an Out of  
Memory error message when I modify the structure of a table.  
 
ANSWER: 
======= 
This problem occurs because of a current limitation in the 
Microsoft Access transaction model (transaction size limited to 4 
MB). 
 
The problem occurs with Counter columns because the table data for 
columns is updated when the new column is added. The update takes 
place in a transaction, and with large tables (greater than 4 MB), 
the update encounters the Microsoft Access transaction size limit. 
When this happens, the transaction rolls back and the Counter 
column is not successfully added. 
 
Use the following steps to add a Counter column to a large table: 
 
1. Copy/paste the table's structure (not the table's data) to a new 
   table. 
2. Add a Counter data type column to the new table. 
3. Create an append query that transfers data from the old table 
   into the new table. 
4. Verify that the new table has the correct data. 
5. Delete the old table. 
6. Rename the new table to the name of the old table. 
 
Microsoft has confirmed this to be a problem in Microsoft Access 
versions 1.0 and 1.1. We are researching this problem and will post new 
information here in the Microsoft Knowledge Base as it becomes  
available. 
------------------------------------------------------------------------ 
 
QUESTION: 
=========   
While modifying a table design, I receive an 'Out of Memory' Error  
message. 
 
When you attempt to make a change to a database, an "Insufficient 
Disk Space or Memory" error message occurs, even if there are ample 
system resources and/or disk space. 
 
ANSWER 
====== 
Microsoft Access has a 4MB transaction limit. All table design 
changes are embedded within a transaction to ensure database 
integrity. As a result, you will get the "Out of memory" error if you 
attempt to update the contents of a table this large or larger. 
 
If, for example, a table contains a field of type "double" that 
you want to change to "integer," there are two ways to do this: 
 
Method 1 
-------- 
1. Select and copy the desired table to the Clipboard. 
2. From the Edit menu, choose Paste (paste only the table structure 
   to a new table name). 
3. Change the data type of the desired column in this new table. 
4. From the Edit menu, choose Paste (paste append the data to this 
   new table). 
 
Method 2 
-------- 
1. Add a new column to the table with the data type you wanted. 
2. Execute an update query, where the new column is assigned the 
   value of the column you wanted to change. 
3. Delete the old column from the table. 
 
Note: You may get similar "out of memory" alerts when using both of 
these methods, but the message boxes should give you the option of 
continuing or canceling. 
 
Microsoft has confirmed this to be a problem in Microsoft Access 
versions 1.0 and 1.1. We are researching this problem and will post new 
information here as it becomes available. 
------------------------------------------------------------------------ 
 
QUESTION: 
========= 
When I attempt to compact a database, I receive an 'Out of Memory' error  
message.  
 
ANSWER: 
======= 
This can be caused by setting MAXBUFFERSIZE greater than 3000 in your  
MSACCESS.INI.  In order to increase performance, many users added  
MAXBUFFERSIZE to there ini file.  If this option is set to greater then  
3000, an 'Out of Memory' error message may occur when compacting the  
database.  To correct this, modify your MSACCESS.INI file, found in your  
Widows directory and reduce this setting to under 3000. 
------------------------------------------------------------------------ 
 
QUESTION: 
========= 
What is the Microsoft Knowledge Base? 
 
ANSWER: 
======= 
Microsoft makes KB articles available to users on the MSKB forum on  
CompuServe.  To view these articles, simply GO MSKB.  A search menu will  
appear allowing you to search by article ID (Q96470) or subject.  
  
The Knowledge Base is a database which will enhance your Microsoft  
products by providing you with access to information previously  
available only to the Microsoft support engineers.   
  
When you elect to search the Knowledge Base, you will find a generous  
array of options by which you can locate answers to your questions. If  
you are searching for general information on your product or maybe just  
trying to find new developments that are on the way, use the options  
which will allow you to search by product name, version or category.  
Once you specify a search term, the Knowledge Base will go to work for  
you, collecting all of the documents it can find related to the criteria  
you supplied.  
 
 

