SQL common data types
Data type defines the type of value stored in the column.
SQL common data types
Each column in a database table requires a name and 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 the type of data that each column in the table will store. A data type is a label that is a guide for SQL to understand what type of data each column is expected to store. It also identifies how SQL interacts with the stored data.
The following table lists the common 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 | Storing TRUE or FALSE value |
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). Accuracy 5. |
INTEGER | Integer value (no decimal point). Accuracy 10. |
BIGINT | Integer value (no decimal point). Accuracy 19. |
DECIMAL(p,s) | Exact value, precision p, number of decimal places s. For example: decimal(5,2) is a number with 3 digits before the decimal point and 2 digits after the decimal point. |
NUMERIC(p,s) | Exact numerical value, precision p, number of decimal places s. (Same as DECIMAL) |
FLOAT(p) | Approximate numerical value, mantissa precision p. A floating-point number in base 10 exponential notation. The size parameter of this type consists of a single number that specifies the minimum precision. |
REAL | Approximate numerical value, mantissa precision 7. |
FLOAT | Approximate numerical value, mantissa precision 16. |
DOUBLE PRECISION | Approximate numerical value, mantissa precision 16. |
DATE | Stores the value of year, month and day. |
TIME | Stores the values of hours, minutes, and seconds. |
TIMESTAMP | Stores the value of year, month, day, hour, minute and second. |
INTERVAL | consists of some integer fields, representing a period of time, depending on the type of interval. |
ARRAY | A fixed-length ordered set of elements |
MULTISET | A variable set of elements Unordered collection of length |
XML | Storing XML data |
SQL Data Type Quick Reference Manual
However, different databases provide different options for data type definition.
The following table shows the common names of some data types on various database platforms:
Data Types | Access | SQLServer | Oracle | MySQL | PostgreSQL |
---|---|---|---|---|---|
##boolean | Yes/NoBit | Byte | N/A | Boolean | |
integer | Number (integer)Int | Number | Int | Integer | IntInteger |
float | Number (single)Float | Real | NumberFloat | Numeric | |
currency | CurrencyMoney | N /A | N/A | Money | |
string (fixed) | N/AChar | Char | Char | Char | |
Text (<256) | Memo (65k+)Varchar | Varchar | Varchar2Varchar | Varchar | |
OLE Object Memo | Binary (fixed up to 8K) | Varbinary (<8K)Image (<2GB) Long | RawBlob | TextBinary | Varbinary
Note: In different databases, the same data type may have different The name. Even if the name is the same, the dimensions and other details may be different! Please always check the documentation! |