The data type you select for each field can
greatly affect the performance and functionality of an application.
Several factors can influence your choice of data type for each field
in a table:
The type of data that’s stored in the field
Whether the field’s contents need to be included in calculations
Whether you need to sort the data in the field
The way you want to sort the data in the field
How important storage space is to you
The type of data you need to store in a field has
the biggest influence on which data type you select. For example, if
you need to store numbers that begin with leading zeros, you can’t
select a Number field because leading zeros entered into a Number field
are ignored. This rule affects data such as zip codes (some of which
begin with leading zeros) and department codes.
If the contents of a field need to be included in
calculations, you must select a Number or Currency data type. You can’t
perform calculations on the contents of fields defined with the other
data types. The only exception to this rule is Date data type fields,
which you can include in date/time calculations.
If it is unimportant that leading zeros be stored in
a field and you just need them to appear on forms and reports, you can
accomplish this by using the Format property of the field.
|
You must also consider whether you will sort or
index the data in a field. You can’t sort the data in OLE Object and
Hyperlink fields, so you shouldn’t select these field types if you must
sort or index the data in the field. Furthermore, you must think about
the way you want to sort the data.
For example, in a Text field, a set of numbers would be sorted in the
order of the numbers’ leftmost character, then the second character
from the left, and so on (that is, 1, 10, 100, 2, 20, 200) because data
in the Text field is sorted as characters rather than numbers. On the
other hand, in a Number or Currency field, the numbers would be sorted
in ascending value order (that is, 1, 2, 10, 20, 100, 200). You might
think you would never want data sorted in a character sequence, but
sometimes it makes sense to sort certain information, such as
department codes, in this fashion. Access 2003 introduced the ability
to sort or group based on a Memo field, but Access performs the sorting
or grouping only based on the first 255 characters. Finally, you should
consider how important disk space is to you. Each field type takes up a
different amount of storage space on a hard disk, and this could be a
factor when you’re selecting a data type for a field.
Nine field types are available in Access: Text,
Memo, Number, Date/Time, Currency, AutoNumber, Yes/No, OLE Object, and
Hyperlink. Table 1 briefly describes the appropriate uses for each field type and the amount of storage space each type needs.
Table 1. Appropriate Uses and Storage Space for Access Field Types
Field Type | Appropriate Uses | Storage Space |
---|
Text | Data
containing text, a combination of text and numbers, or numbers that
don’t need to be included in calculations. Examples are names,
addresses, department codes, and phone numbers. | Based on what’s actually stored in the field; ranges from 0 to 255 bytes. |
Memo | Long text and numeric strings. Examples are notes and descriptions. | Ranges from 0 to 65,536 bytes. |
Number | Data that’s included in calculations (excluding money). Examples are ages, codes (such as employee IDs), and payment methods. | 1, 2, 4, or 8 bytes, depending on the field size selected (or 16 bytes for replication ID). |
Date/Time | Dates and times. Examples are date ordered and birth date. | 8 bytes. |
Currency | Currency values. Examples are amount due and price. | 8 bytes. |
AutoNumber | Unique sequential or random numbers. Examples are invoice numbers and project numbers. | 4 bytes (16 bytes for replication ID). |
Yes/No | Fields
that contain one of two values (for example, yes/no, true/false).
Sample uses are indicating bills paid and tenure status. | 1 bit. |
OLE Object | Objects such as Word documents or Excel spreadsheets. Examples are employee reviews and budgets. | 0 bytes to 1GB, depending on what’s stored within the field. |
Hyperlink | Text
or a combination of text and numbers, stored as text and used as a
hyperlink for a Web address (uniform resource locator [URL]) or a
universal naming convention (UNC) path. Examples are Web pages and
network files. | 0 to 2,048 bytes for text for each of the three parts that compose the address (up to 64,000 characters total). |
The most difficult part of selecting a field type is
knowing which type is best in each situation. The following detailed
descriptions of each field type and when you should use them should
help you with this process.
Although Microsoft loosely considers Lookup Wizard a
field type, it is really not its own field type. You use it to create a
field that allows the user to select a value from another table or from
a list of values via a combo box that the wizard helps define for you.
As far as storage, it requires that same storage size as the primary
key for the lookup field.
|
Text Fields: The Most Common Field Type
Most
fields are Text fields. Many developers don’t realize that it’s best to
use Text fields for any numbers that are not used in calculations.
Examples of such numbers are phone numbers, part numbers, and zip
codes. Although the default size for a Text field is 50 characters, you
can store up to 255 characters in a Text field. Because Access
allocates disk space dynamically, a large field size doesn’t use hard
disk space, but you can improve performance if you allocate the
smallest field size possible. You can control the maximum number of
characters allowed in a Text field by using the FieldSize property.
The Hyperlink field type contains a hyperlink
object. The hyperlink object consists of three parts. The first part is
called the display text; it’s the text that appears in the field or control. The second part is the actual file path (UNC path) or page (URL) the field is referring to. The third part is the subaddress, a location within the file or page.
|
Memo Fields: For Long Notes and Comments
A Memo field can store up to 65,536 characters of
text, meaning that it can hold up to 16 pages of text for each record.
Memo fields are excellent for any types of notes you want to store with
table data. Remember that in Access 2010 you can sort by a Memo field.
Number Fields: For When You Need to Calculate
You use Number fields to store data that you must
include in calculations. If currency amounts are included in
calculations or if calculations require the highest degree of accuracy,
you should use a Currency field rather than a Number field.
The Number field is actually several types of fields
in one because Access 2010 offers seven sizes of numeric fields. Byte
can store integers from 0 to 255, Integer can hold whole numbers from
–32768 to 32767, and Long Integer can hold whole numbers ranging from
less than –2 billion to just over 2 billion. Although all three of
these sizes offer excellent performance, each type requires an
increasingly large amount of storage space. Two of the other numeric
field sizes, Single and Double, offer floating decimal points and,
therefore, much slower performance than integer and long integer.
Single can hold fractional numbers to 7 significant digits; Double
extends the precision to 14 significant digits. Decimal, a numeric data
type that was introduced with Access 2002, allows storage of very large
numbers and provides decimal precision up to 28 digits!
Date/Time Fields: For Tracking When Things Happened
You
use the Date/Time field type to store valid dates and times. Date/Time
fields allow you to perform date calculations and make sure dates and
times are always sorted properly. Access actually stores the date or
time internally as an 8-byte floating-point number. Access represents
time as a fraction of a day.
Currency Fields: For Storing Money
The Currency field is a number field that is used
when currency values are being stored in a table. A Currency field
prevents the computer from rounding off data during calculations. It
holds 15 digits of whole dollars, plus accuracy to one-hundredth of a
cent. Although very accurate, this type of field is quite slow to
process.
Any date and time settings you establish in the
Windows Control Panel are reflected in your data. For example, if you
modify Short Date Style in Regional Settings within the Control Panel,
your forms, reports, and datasheets will immediately reflect those
changes.
|
AutoNumber Fields: For Unique Record Identifiers
The AutoNumber field in Access 2010 automatically
generates AutoNumber field values when the user adds a record. In
Access 2.0, counter values have to be sequential. The AutoNumber field
type in Access 2010 can be either sequential or random. The random
assignment is useful when several users are adding records offline
because it’s unlikely that Access will assign the same random value to
two records.
Any changes to the currency format made in the
Windows Control Panel are reflected in your data. Of course, Access
doesn’t automatically perform any actual conversion of currency
amounts. As with dates, if you modify the currency symbol in Regional
Settings within the Control Panel, your forms, reports, and datasheets
will immediately reflect those changes.
|
You should note a few important points about
sequential AutoNumber fields. If a user deletes a record from a table,
its unique number is lost forever. Likewise, if a user is adding a
record but cancels the action, the unique counter value for that record
is lost forever. If this behavior is unacceptable, you can generate
your own counter values.
Yes/No Fields: For When One of Two Answers Is Correct
You
should use Yes/No fields to store a logical true or false. What Access
actually stores in the field is -1 for yes, 0 for no, or Null for no
specific choice. The display format for the field determines what the
user actually sees (normally Yes/No, True/False, On/Off, or a third
option [Null] if you set the TripleState property of the
associated control on a form to True). Yes/No fields work efficiently
for any data that can have only a true or false value. Not only do they
limit the user to valid choices, but they also take up only 1 bit of
storage space.
OLE Object Fields: For Storing Just About Anything
OLE Object fields are designed to hold data from any
OLE server application that is registered in Windows, including
spreadsheets, word processing documents, sound, and video. There are
many business uses for OLE Object fields, such as storing resumes,
employee reviews, budgets, or videos. However, in many cases, it is
more efficient to use a Hyperlink field to store a link to the document
rather than store the document itself in an OLE Object field.
Hyperlink Fields: For Linking to the Internet
Hyperlink fields are used to store uniform resource
locator addresses, which are links to web pages on the Internet or on
an intranet, or UNC paths, which are links to a file location path. The
Hyperlink field type is broken into three parts:
After the user places an entry in a Hyperlink field, the entry serves as a direct link to the file or page it refers to.