Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

SQL MS Access, MySQL, and SQL Server Data Types

SQL data types for various databases


The data types and ranges used by Microsoft Access, MySQL, and SQL Server.


Microsoft Access data types

Data Type Description Storage
Text For text or combinations of text and numbers. Up to 255 characters.
Memo Memo is for larger amounts of text. Stores up to 65,536 characters. **Note:** Memo fields cannot be sorted. However, they are searchable.
Byte Allows numbers from 0 to 255. 1 byte
Integer Allows all numbers between -32,768 and 32,767. 2 bytes
Long Allows all numbers between -2,147,483,648 and 2,147,483,647. 4 bytes
Single Single-precision floating point. Handles most decimals. 4 bytes
Double Double-precision floating point. Handles most decimals. 8 bytes
Currency For currency. Supports 15 digits of dollars plus 4 decimal places. **Tip:** You can choose which country's currency to use. 8 bytes
AutoNumber The AutoNumber field automatically assigns a number to each record, usually starting from 1. 4 bytes
Date/Time For dates and times 8 bytes
Yes/No A logical field that can be displayed as Yes/No, True/False, or On/Off. In code, use the constants True and False (equivalent to 1 and 0). **Note:** Null values are not allowed in Yes/No fields 1 bit
Ole Object Can store pictures, audio, video, or other BLOBs (Binary Large OBjects). Up to 1GB
Hyperlink Contains links to other files, including web pages.
Lookup Wizard Allows you to create a list of options that can be selected from a drop-down list. 4 bytes

MySQL data types

In MySQL, there are three main types: Text, Number, and Date/Time.

Text types:

Data Type Description
CHAR(size) Holds a fixed-length string (which can contain letters, numbers, and special characters). Specify the length of the string in parentheses. Up to 255 characters.
VARCHAR(size) Holds a variable-length string (which can contain letters, numbers, and special characters). Specify the maximum length of the string in parentheses. Up to 255 characters. **Note:** If the value is longer than 255, it is converted to the TEXT type.
TINYTEXT Stores a string with a maximum length of 255 characters.
TEXT Stores a string with a maximum length of 65,535 characters.
BLOB For BLOBs (Binary Large OBjects). Stores up to 65,535 bytes of data.
MEDIUMTEXT Stores a string with a maximum length of 16,777,215 characters.
MEDIUMBLOB For BLOBs (Binary Large OBjects). Stores up to 16,777,215 bytes of data.
LONGTEXT Stores a string with a maximum length of 4,294,967,295 characters.
LONGBLOB For BLOBs (Binary Large OBjects). Stores up to 4,294,967,295 bytes of data.
ENUM(x,y,z,etc.) Allows you to enter a list of possible values. You can list up to 65,535 values in an ENUM list. If the inserted value is not present in the list, an empty value is inserted.

Note:These values are sorted in the order you entered them.

Possible values can be entered in this format: ENUM('X','Y','Z')

SET Similar to ENUM, except that SET can contain at most 64 list items and SET can store more than one selection.

Number types:

Data Type Description
TINYINT(size) Signed -128 to 127, unsigned 0 to 255.
SMALLINT(size) Signed range -32768 to 32767, unsigned 0 to 65535, size defaults to 6.
MEDIUMINT(size) Signed range -8388608 to 8388607, unsigned range 0 to 16777215. size defaults to 9
INT(size) Signed range -2147483648 to 2147483647, unsigned range 0 to 4294967295. size defaults to 11
BIGINT(size) Signed range is -9223372036854775808 to 9223372036854775807, unsigned range is 0 to 18446744073709551615. size defaults to 20
FLOAT(size,d) A small number with a floating decimal point. Specify the maximum number of digits to display in the size parameter. Specify the maximum number of digits to the right of the decimal point in the d parameter.
DOUBLE(size,d) A large number with a floating decimal point. Specify the maximum number of digits to display in the size parameter. Specify the maximum number of digits to the right of the decimal point in the d parameter.
DECIMAL(size,d) The DOUBLE type stored as a string, allowing a fixed decimal point. Specify the maximum number of digits to display in the size parameter. Specify the maximum number of digits to the right of the decimal point in the d parameter.

Note:The size above does not represent the specific length stored in the database; for example, int(4) does not mean it can only store 4-digit numbers.

In fact, int(size) has nothing to do with how much storage space is used. int(3), int(4), and int(8) all occupy 4 bytes of storage on disk. Apart from a slight difference in how they are displayed to the user, the int(M) and int data types are the same.

For example:

1. The value of int is 10 (with zerofill specified)


int(9) displays as 000000010 int(3) displays as 010

Only the display length differs; both occupy four bytes of space.

Date types:

Data Type Description
DATE() Date. Format: YYYY-MM-DD

Note:The supported range is from '1000-01-01' to '9999-12-31'

DATETIME() *A combination of date and time. Format: YYYY-MM-DD HH:MM:SS

Note:The supported range is from '1000-01-01 00:00:00' to '9999-12-31 23:59:59'

TIMESTAMP() *Timestamp. TIMESTAMP values are stored using the number of seconds since the Unix epoch ('1970-01-01 00:00:00' UTC). Format: YYYY-MM-DD HH:MM:SS

Note:The supported range is from '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC

TIME() Time. Format: HH:MM:SS

Note:The supported range is from '-838:59:59' to '838:59:59'

YEAR() Years in 2-digit or 4-digit format.

Note:Allowed values for the 4-digit format: 1901 to 2155. Allowed values for the 2-digit format: 70 to 69, representing 1970 to 2069.

*Even though DATETIME and TIMESTAMP return the same format, they work very differently. In INSERT or UPDATE queries, TIMESTAMP automatically sets itself to the current date and time. TIMESTAMP also accepts various formats, such as YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD, or YYMMDD.


SQL Server data types

String types:

Data Type Description Storage
char(n) Fixed-length string. Up to 8,000 characters. Defined width
varchar(n) Variable-length string. Up to 8,000 characters. 2 bytes + number of chars
varchar(max) Variable-length string. Up to 1,073,741,824 characters. 2 bytes + number of chars
text Variable-length string. Up to 2GB of text data. 4 bytes + number of chars
nchar Fixed-length Unicode string. Up to 4,000 characters. Defined width x 2
nvarchar Variable-length Unicode string. Up to 4,000 characters.
nvarchar(max) Variable-length Unicode string. Up to 536,870,912 characters.
ntext Variable-length Unicode string. Up to 2GB of text data.
bit Allows 0, 1, or NULL
binary(n) Fixed-length binary string. Up to 8,000 bytes.
varbinary Variable-length binary string. Up to 8,000 bytes.
varbinary(max) Variable-length binary string. Up to 2GB.
image Variable-length binary string. Up to 2GB.

Number types:

Data Type Description Storage
tinyint Allows all numbers from 0 to 255. 1 byte
smallint Allows all numbers between -32,768 and 32,767. 2 bytes
int Allows all numbers between -2,147,483,648 and 2,147,483,647. 4 bytes
bigint Allows all numbers between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807. 8 bytes
decimal(p,s) Numbers with fixed precision and scale.

Allows numbers from -10^38 +1 to 10^38 -1.

The p parameter indicates the maximum number of digits that can be stored (to the left and right of the decimal point). p must be a value between 1 and 38. The default is 18.

The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value between 0 and p. The default is 0.

5-17 bytes
numeric(p,s) Numbers with fixed precision and scale.

Allows numbers from -10^38 +1 to 10^38 -1.

The p parameter indicates the maximum number of digits that can be stored (to the left and right of the decimal point). p must be a value between 1 and 38. The default is 18.

The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value between 0 and p. The default is 0.

5-17 bytes
smallmoney Currency data between -214,748.3648 and 214,748.3647. 4 bytes
money Currency data between -922,337,203,685,477.5808 and 922,337,203,685,477.5807. 8 bytes
float(n) Floating-precision numeric data from -1.79E + 308 to 1.79E + 308.

The n parameter indicates whether the field stores 4 bytes or 8 bytes. float(24) stores 4 bytes, while float(53) stores 8 bytes. The default value of n is 53.

4 or 8 bytes
real Floating-precision numeric data from -3.40E + 38 to 3.40E + 38. 4 bytes

Date types:

Data Type Description Storage
datetime From January 1, 1753 to December 31, 9999, with an accuracy of 3.33 milliseconds. 8 bytes
datetime2 From January 1, 1753 to December 31, 9999, with an accuracy of 100 nanoseconds. 6-8 bytes
smalldatetime From January 1, 1900 to June 6, 2079, with an accuracy of 1 minute. 4 bytes
date Stores only the date. From January 1, 0001 to December 31, 9999. 3 bytes
time Stores only the time. Accuracy of 100 nanoseconds. 3-5 bytes
datetimeoffset Same as datetime2, plus a time zone offset. 8-10 bytes
timestamp Stores a unique number that is updated whenever a row is created or modified. timestamp values are based on an internal clock and do not correspond to real time. Each table can have only one timestamp variable.  

Other data types:

Data Type Description
sql_variant Stores up to 8,000 bytes of data of various data types, except text, ntext, and timestamp.
uniqueidentifier Stores a globally unique identifier (GUID).
xml Stores XML-formatted data. Up to 2GB.
cursor Stores a reference to a pointer used for database operations.
table Stores a result set for later processing.