MS-Access / Getting Started

SQL Data Types

When you create column names for a table, each column must contain a data type. A data type specifies the type of data a column can store. For example, if you create a column that can only store numbers, you must assign it a specific data type that will only allow numbers to be stored in the column. SQL view supports a variety of different data types. Tables-2 and 3 list data types used in Microsoft Access.

Table-2: Common Microsoft Access data types
Data TypeDescription
Numeric:
DECIMALAn exact numeric data type that holds values from -10^28-1 to 10^28-1.
FLOATStores double-precision floating-point values.
INTEGERAlso called INT. Stores long integers from -2,147,483,648 to 2,147,483,647.
REALStores single-precision floating-point values.
SMALLINTStores integers from -32,768 to 32,767.
TINYINTStores integers from 0 to 255.
String:
CHARA fixed-length data type that stores a combination of text and numbers up to 255 characters.
TEXTA variable-length data type that stores a combination of text and numbers up to 255 characters. The length is determined by the Field size property. The string can contain any ASCII characters including letters, numbers, special characters, and nonprinting characters.
Miscellaneous:
BINARYEnables you to store any type of data in a field. No transformation of the data is made in this type of field.
BITUsed to store one of two types of values. For example, true/false, yes/no, or on/off.
COUNTERStores a long integer value that automatically increments whenever a new record is inserted.
DATETIMEStores date and time values for the years 100 to 9999.
IMAGEUsed to store Object Linking and Embedding (OLE) objects. For example, pictures, audio, and video.
MONEYStores currency values and numeric data used in mathematical calculations.
UNIQUEIDENTIFIERA unique identification number used with remote procedure calls.
Table-3. Additional Microsoft Access data types
Data TypeDescription
CurrencyUsed for monetary calculations.
MemoVariable-length text field from 1 to 65,536 characters in length.
NumberNumerical data that can be used in all forms of calculations except those dealing with money. The Field size property determines the number of bytes that are used to store the number and, subsequently, the number range.
OLE ObjectAny linked or embedded object including such things like images, Excel spreadsheets, Word documents, or virtually anything else.
Yes/NoBoolean values, which have only two states like yes/no, true/false, or on/off.

Note: Some data types do not require a field size.

Looking at the list of above data types the astute reader will ask "How does this list of data types compare to the standard Access data types that appear when building a table manually?" The answer is Microsoft has a very elegant solution to the different types - a list of synonyms (Table-4). In other words, when you manually build a table you are actually using the data types listed above, but you are using the old Access naming conventions.

Table-4. Microsoft Access data types and synonyms
ANSI SQL Data TypeMicrosoft Access SQL Data TypeSynonym
BIT, BIT VARYINGBINARYVARBINARY, BINARY VARYING, BIT VARYING
Not supportedBITBOOLEAN, LOGICAL, LOGICAL1, YESNO
Not supportedTINYINTINTEGER1, BYTE
Not supportedCOUNTERAUTOINCREMENT
Not supportedMONEYCURRENCY
DATE, TIME, TIMESTAMPDATETIMEDATE, TIME
Not supportedUNIQUEIDENTIFIERGUID
DECIMALDECIMALNUMERIC, DEC
REALREALSINGLE, FLOAT4, IEEESINGLE
DOUBLE PRECISION, FLOATFLOATDOUBLE, FLOAT8, IEEEDOUBLE, NUMBER
SMALLINTSMALLINTSHORT, INTEGER2
INTEGERINTEGERLONG, INT, INTEGER4
INTERVALNot supported
Not supportedIMAGELONGBINARY, GENERAL, OLEOBJECT
Not supportedTEXTLONGTEXT, LONGCHAR, MEMO, NOTE, NTEXT
CHARACTER, CHARACTER VARYING, NATIONAL CHARACTER, NATIONAL CHARACTER VARYINGCHARTEXT(n), ALPHANUMERIC, CHARACTER, STRING, VARCHAR, CHARACTER VARYING, NCHAR, NATIONAL CHARACTER, NATIONAL CHAR, NATIONAL CHARACTER VARYING, NATIONAL CHAR VARYING

Example-A

In this example, we'll create a table that demonstrates three data types described above. The following SQL script creates a table named TableOne with three columns (Field1, Field2, and Field3). Each column specifies a different data type (COUNTER, TEXT, and CURRENCY).

    CREATE TABLE TableOne
    (
    Field1 COUNTER (4),
    Field2 TEXT,
    Field3 CURRENCY
    );

In this SQL script, the Field1 column contains a COUNTER data type. The COUNTER data type stores a long integer value that automatically increments whenever a new record is inserted. Notice the number 4 is defined immediately following the COUNTER data type. This number causes the Field1 column to default to 4 and increment thereafter. If you do not specify a number with the COUNTER data type, the column will begin incrementing with the number 1.

The Field2 column contains a TEXT data type. The TEXT data type is a variable-length data type that stores a combination of text and numbers up to 255 characters.

The Field3 column contains a CURRENCY data type.

[Previous] [Contents] [Next]