SQL General Data Types
A data type defines the kind of value that can be stored in a column.
SQL General Data Types
Every column in a database table is required to have a name and a data type. Each column in a database table is required to have a name and a data type.
SQL developers must decide, when creating a SQL table, what type of data each column in the table will store. A data type is a label, a guide that helps SQL understand what type of data each column is expected to store, and it also identifies how SQL interacts with the stored data.
The following table lists the general data types in SQL:
| Data Type | Description |
|---|---|
| CHARACTER(n) | Character/string. Fixed length n. |
| VARCHAR(n) or | |
| CHARACTER VARYING(n) | Character/string. Variable length. Maximum length n. |
| BINARY(n) | Binary string. Fixed length n. |
| BOOLEAN | Stores TRUE or FALSE values |
| VARBINARY(n) or | |
| BINARY VARYING(n) | Binary string. Variable length. Maximum length n. |
| INTEGER(p) | Integer value (no decimal point). Precision p. |
| SMALLINT | Integer value (no decimal point). Precision 5. |
| INTEGER | Integer value (no decimal point). Precision 10. |
| BIGINT | Integer value (no decimal point). Precision 19. |
| DECIMAL(p,s) | Exact numeric value, precision p, scale s (number of digits after the decimal point). For example: decimal(5,2) is a number with 3 digits before the decimal point and 2 digits after it. |
| NUMERIC(p,s) | Exact numeric value, precision p, scale s (number of digits after the decimal point). (Same as DECIMAL) |
| FLOAT(p) | Approximate numeric value, mantissa precision p. A floating-point number using base-10 exponential notation. The size parameter of this type consists of a single number specifying the minimum precision. |
| REAL | Approximate numeric value, mantissa precision 7. |
| FLOAT | Approximate numeric value, mantissa precision 16. |
| DOUBLE PRECISION | Approximate numeric value, mantissa precision 16. |
| DATE | Stores year, month, and day values. |
| TIME | Stores hour, minute, and second values. |
| TIMESTAMP | Stores year, month, day, hour, minute, and second values. |
| INTERVAL | Consists of several integer fields representing a period of time, depending on the type of interval. |
| ARRAY | An ordered collection of elements with fixed length |
| MULTISET | An unordered collection of elements with variable length |
| XML | Stores XML data |
SQL Data Types Quick Reference
However, different databases offer different choices for data type definitions.
The following table shows the common names of some data types across various database platforms:
| Data Type | Access | SQLServer | Oracle | MySQL | PostgreSQL |
|---|---|---|---|---|---|
| boolean | Yes/No | Bit | Byte | N/A | Boolean |
| integer | Number (integer) | Int | Number | Int | |
| Integer | Int | ||||
| Integer | |||||
| float | Number (single) | Float | |||
| Real | Number | Float | Numeric | ||
| currency | Currency | Money | N/A | N/A | Money |
| string (fixed) | N/A | Char | Char | Char | Char |
| string (variable) | Text (<256) | ||||
| Memo (65k+) | Varchar | Varchar | |||
| Varchar2 | Varchar | Varchar | |||
| binary object | OLE Object Memo | Binary (fixed up to 8K) |
Varbinary (<8K)
Image (<2GB) | Long
Raw | Blob
Text | Binary
Varbinary |
![]() |
Note:In different databases, the same data type may have different names. Even if the names are the same, the size and other details may differ! Always check the documentation! |
|---|
