Vous êtes sur la page 1sur 4

1

Field Data Types


Once you have identified the tables and the fields for your database, the next step is to determine each fields
data type. With any relational database management system, you need to define what kind of information
each field will contain. In most relational database management systems, there are three primary categories of
field types:
1. Text 2. Numbers 3. Dates and Times
Within each of these primary categories, there are variations of these categories, some of which may be
specific to individual RDMSs. I will highlight particular differences as they arise.
It is important to give careful thought and consideration to field types because they dictate what information
can be stored and how it is stored which may affect database performance.

Microsoft Access Data Types


Below is a list of data types for Microsoft Access (adapted from Schwartz S. Microsoft Office Access 2003.
A visual quickstart guide. Peachpit Press: Berkeley 2004).
In Microsoft Access, each field can be one of the following data types:

1. Text: a Text field can store any combination of typed characters: letters, numbers, and punctuation.
2. Memo: a Memo field is an extra large Text field (up to 65,535 characters). When sorting on a Memo
field, Access only considers the first 255 characters.
3. Number: a Number field is used to store most types of numeric data (with the exception of monetary
amounts which can be stored using the Currency field type).
4. Currency: this data type has been designed specifically to store currency amounts and prevent
rounding errors.
5. Auto Number: the Auto Number data type is used to automatically assign a new number to a primary
key field, increasing the previously assigned number by one. Data stored in an Auto Number field
cannot be edited.
6. Date/Time: a Date/Time field is used to store dates or times. A specific format to display dates and
times can be selected.
7. Yes/No: a Yes/No field is the Access data type for recording one of two opposing values. Yes/No
fields can be formatted as Yes/No, True/False, or On/Off (although all are equivalent). Every Yes/No
field is formatted as a single check box; checked is “Yes”, “True”, or “On” whereas unchecked is
“No”, “False”, or “Off”.
8. OLE Object: Object Linking and Embedding (OLE) Object data types enable you to embed or link to
documents created in other programs, such as worksheets created in MS Excel, images (eg, gif, or jpg
files), or word processing files (eg, doc files); one can either embed the object in the Access data file
or link the object to the database, thereby storing a pointer or a reference to the original document.
OLE is the technology which allows an object (such as a spreadsheet) to be embedded (and/or linked)
inside of another document (like a word processor document).
9. Hyperlink: the Hyperlink data type enables you to store a “clickable” address in the field. For
example:
a. http://
b. mailto:
c. ftp://
10. Lookup Wizard: a Lookup Wizard field type enables a field to display a drop-down list of values
from which the user can choose; this list of values can come from another table, a query, or event he
same table.
2
A Review of Bits and Bytes
(This section has been adapted from Marshall Brain’s article on “How Bits and Bytes Work”
In order to understand a little about field types and their bytes, it’s important to review briefly what bytes (and
bits) are.
Let’s first review the concept of decimal numbers. I think everyone is familiar with decimal places and digits
of a decimal number. Each digit can range from 0 to 9, that is, ten possible values. For example, we know
that the number 1,488 has four digits with four decimal places: 8 ones, 8 tens, 4 hundreds, and 1 thousands.
So the number 1,488 could be expressed as:

(1*1000) + (4*100) + (8*10) + (8*1) = 1000 + 400 + 80 + 8 = 1,488

Similarly, we could express the same number in terms of powers of 10:

(1*10^3) + (4*10^2) + (8*10^1) + (8*10^0) = 1000 + 400 + 80 + 8 = 1,488


Recall, anything to the zero power is equal to 1.
Bits and bytes could be viewed in a similar way. Computers use the base-2 system known as the binary
number system just as the base-10 number system is known as the decimal number system. Each binary digit
(also called a “bit” for Binary digIT) can only take on one of two values, 1 or 0, instead of 0 to 9 like the
decimal system. So the binary number 1100 would represent:

(1*2^3) + (1*2^2) + (0*2^1) + (0*2^0) = 12

This time we use base of 2 instead of base of 10.

A collection of 8 bits is known as one byte. With 8 bits in a byte, one can represent 256 values ranging from
0 to 255:
00000000 = (0*2^7) + (0*2^6) + (0*2^5) + (0*2^4) + (0*2^3) + (0*2^2) +
(0*2^1) + (0*2^0)
=0

11111111 = (1*2^7) + (1*2^6) + (1*2^5) + (1*2^4) + (1*2^3) + (1*2^2) +


(1*2^1) + (1*2^0)
= 255

Three bytes (24 bits) can then represent a number ranging from 0 to 16,777,215.

000000000000000000000000 = (0*2^23) + (0*2^22) + (0*2^21) + …+ (0*2^4) +


(0*2^3) + (0*2^2) + (0*2^1) + (0*2^0)
=0

111111111111111111111111 = (1*2^23) + (1*2^22) + (1*2^21) + …+ (1*2^4) +


(1*2^3) + (1*2^2) + (1*2^1) + (1*2^0)
= 16,777,215

Bytes are used to hold individual characters in a text document. For example, 00100000 is equal to 32 which
is the numeric code for “space”. So text characters are coded as numbers which are stored as bytes in a
computer file. The computer usually stores each character in 1 byte.
3
Working with Database Fields

Microsoft Access database fields are created by entering a field name and a field data type in each row of the field
entry area of the database table window. The field description is an option to identify the fields purpose; it appears
in the status bar during data entry. After you enter each field's name and data type, you can specify how each field
is used by entering properties in the property area. Before you enter any properties, however, you should enter all
of you field’s names and data types.

Naming a Database Field

A field name identifies the field to both you and to Microsoft Access. For information regarding field names please
see the article:
Specifying a Microsoft Access Data Type
After you name a field, you must decide what type of data the field will hold. Before you begin entering data, you
should have a grasp of the data types that your system will use. Ten basic data types are shown in the table below;
some data types (such as numbers) have several options:

Microsoft Access Data Types

Data Type Use For Size

Up to 255 characters. Microsoft Access only


Text or combinations of text and numbers, such as stores the characters entered in a field; it
addresses. Also numbers that do not require does not store space characters for unused
Text
calculations, such as phone numbers, part numbers, or positions in a Text field. To control the
postal codes. maximum number of characters that can be
entered, set the Field Size property.

Lengthy text and numbers, such as notes or


Memo Up to 64,000 characters.
descriptions.

Numeric data to be used for mathematical calculations,


1, 2, 4, or 8 bytes. 16 bytes for Replication ID
except calculations involving money (use Currency
Number (GUID) only.
type). Set the Field Size property to define the specific
Number type.

Date/Time Dates and times. 8 bytes.

Currency values. Use the Currency data type to prevent


Currency rounding off during calculations. Accurate to 15 digits to 8 bytes.
the left of the decimal point and 4 digits to the right.

Unique sequential (incrementing by 1) or random 4 bytes. 16 bytes for Replication ID (GUID)


AutoNumber
numbers automatically inserted when a record is added. only.

Fields that will contain only one of two values, such as


Yes/No 1 bit.
Yes/No, True/False, On/Off.

Objects (such as Microsoft Word documents, Microsoft


Excel spreadsheets, pictures, sounds, or other binary
data), created in other programs using the OLE protocol,
OLE Object Up to 1 gigabyte (limited by disk space).
that can be linked to or embedded in a Microsoft Access
table. You must use a bound object frame in a form or
report to display the OLE object.

Field that will store hyperlinks. A hyperlink can be a UNC


Hyperlink Up to 64,000 characters.
path or a URL.

Creates a field that allows you to choose a value from


Lookup The same size as the primary key field that is
another table or from a list of values using a combo box.
Wizard also the Lookup field; typically 4 bytes.
Choosing this option in the data type list starts a

For numeric data types, the field size enables you to further define the type of number, which in turn determines
the storage size. The table below shows the seven possible settings in the Numeric Field Size property.
4
You should make the field size the smallest one possible; Access runs faster with smaller field sizes. Note the first
three settings don’t use decimal points, but allow increasingly larger positive or negative numbers. Single and
double permit even larger numbers: Single gives you 7 decimal places, and double allows 15. Use the Double
setting when you need many decimal places or very large numbers.

Numeric Field Size Properties

Decimal Storage
Setting Description
Precision Size

Byte Stores numbers from 0 to 255 (no fractions). None 1 byte

Integer Stores numbers from –32,768 to 32,767 (no fractions). None 2 bytes

Long (Default) Stores numbers from –2,147,483,648 to 2,147,483,647 (no


None 4 bytes
Integer fractions).

Stores numbers from -10^38 -1 through 10^38 -1 (.adp)


Decimal 28 12 bytes
Stores numbers from-10^28 -1 through 10^28 -1 (.mdb)

Stores numbers from –3.402823E38 to


Single –1.401298E–45 for negative values and from 7 4 bytes
1.401298E–45 to 3.402823E38 for positive values.

Stores numbers from –1.79769313486231E308 to –4.94065645841247E–324


Double for negative values and from 1.79769313486231E308 to 4.94065645841247E– 15 8 bytes
324 for positive values.

Replication
Globally unique identifier (GUID) N/A 16 bytes
ID

Caution: If you convert a large Field Size setting to a smaller one in a field that already contains data, you might
lose data. For example, if you change the Field Size setting for a Text data type field from 255 to 50, data beyond
the new 50-character setting will be discarded.
If the data in a Number data type field doesn't fit in a new Field Size setting, fractional numbers may be rounded
or you might get a Null value. For example, if you change from a Single to an Integer field size, fractional values
will be rounded to the nearest whole number and values greater than 32,767 or less than –32,768 will result in null
fields.
Tip: You can use the Currency data type if you plan to perform many calculations on a field that contains data with
one to four decimal places. Single and Double data type fields require floating-point calculation. Currency data
type fields use a faster fixed-point calculation.

Vous aimerez peut-être aussi