SQL Common Data Types
Data types define the kind of values stored in a column.
SQL Common Data Types
Each column in a database table requires 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 what type of data will be stored in each column when creating an SQL table. A data type is a label and a guideline for SQL to understand what kind of data is expected in each column, and it also identifies how SQL will interact with the stored data.
The following table lists common data types in SQL:
Data Type | Description |
---|---|
CHARACTER(n) | Character/string. Fixed length n. |
VARCHAR(n) or <br>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 <br>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. For example, decimal(5,2) is a number with 3 digits before the decimal point and 2 digits after. |
NUMERIC(p,s) | Exact numeric value, precision p, scale s. (Same as DECIMAL) |
FLOAT(p) | Approximate numeric value, mantissa precision p. A floating-point number using base-10 exponent notation. The size parameter consists of a single number that specifies 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 interval type. |
ARRAY | Fixed-length ordered collection of elements |
MULTISET | Variable-length unordered collection of elements |
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 on various database platforms:
Data Type | Access | SQLServer | Oracle | MySQL | PostgreSQL |
---|---|---|---|---|---|
boolean | Yes/No | Bit | Byte | N/A | Boolean |
integer | Number (integer) | Int | Number | Int <br>Integer | Int <br>Integer |
float | Number (single) | Float <br>Real | Number | Float | Numeric |
currency | Currency | Money | N/A | N/A | Money |
string (fixed) | N/A | Char | Char | Char | Char |
string (variable) | Text (<256) <br>Memo (65k+) | Varchar | Varchar <br>Varchar2 | Varchar | Varchar |
binary object | OLE Object Memo | Binary (fixed up to 8K) <br>Varbinary (<8K) <br>Image (<2GB) | Long <br>Raw | Blob <br>Text | Binary <br>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 vary! <br>Always check the documentation! | | --- | --- |