Compatible Compatible with warning Not compatible Unknown
Example of data type | MySQL MariaDB |
Oracle Database |
PostgreSQL | Microsoft SQL Server |
IBM DB2 | SQLite | Other database systems |
ANSI/ISO standard |
Universal alternative | |
---|---|---|---|---|---|---|---|---|---|---|
INT | Yes | NUMBER(38) | Yes | Yes | Yes | INT or TEXT | Access Firebird Interbase | Informix CUBRID Sybase | SQL-92 | INTEGER |
INTEGER | Yes | NUMBER(38) | Yes | Yes | Yes | INT or TEXT | Microsoft Access | SQL-92 | INT | |
SMALLINT | Yes | NUMBER(38) | Yes | Yes | Yes | INT or TEXT | Access Informix CUBRID | Firebird & Sybase | SQL-92 | |
DECIMAL(9,2) | max 65 digits | NUMBER(9,2) | 1000 digits or more | max 38 digits | Yes | REAL or TEXT | Informix | Microsoft Access | SQL-92 | NUMERIC(9,2) |
NUMERIC(9,2) | max 65 digits | NUMBER(9,2) | 1000 digits or more | max 38 digits | Yes | REAL or TEXT | Microsoft Access | SQL-92 | DECIMAL(9,2) | |
DOUBLE PRECISION | double-precision (8 bytes) | FLOAT(126) | 15 digits (8 bytes) | FLOAT(53) | double-precision | REAL or TEXT | Microsoft Access | Informix | SQL-92 | FLOAT(53) |
FLOAT(24) | max 53 | max 126 | max 53 | max 53 | max 53 | REAL or TEXT | SQL-92 | |||
CHAR(255) | max 255 | max 2000 | max 10485760 | Yes | max 255 254 before v10 |
unlimited TEXT | Firebird Sybase Informix | CUBRID: max 32767 | SQL-92 | |
VARCHAR(126) | max 65535 | max 4000 or 32767 | max 10485760 | max 8000 | max 32672 | unlimited TEXT | Informix: max 255 | Microsoft Access | SQL-92 | |
Column properties | ||||||||||
NOT NULL | Yes | Yes | Yes | Yes | Yes | Yes | ||||
PRIMARY KEY | Yes | Yes | Yes | Yes | Yes | Yes | ||||
DEFAULT value | Yes | Yes | Yes | Yes | Yes | Yes | SQL-92 | |||
UNIQUE | Yes | Yes | Yes | Yes | Yes | Yes | ||||
Other column properties | ||||||||||
AUTO_INCREMENT | Yes | No | ? | No | No | No | Sybase | INSERT ... SELECT COALESCE(MAX(id)+1,1)... | ||
IDENTITY(1,1) | No | No | ? | Yes | ? | No | Sybase | INSERT ... SELECT COALESCE(MAX(id)+1,1)... | ||
GENERATED BY DEFAULT AS IDENTITY | ? | since 12c (2013) | ? | ? | Yes | No | INSERT ... SELECT COALESCE(MAX(id)+1,1)... | |||
UNSIGNED | integer | No | No | No | No | signed INT | Access Firebird CUBRID | Sybase | INSERT INTO tab (col) VALUES (int-2147483647) SELECT col+2147483647 FROM tab |
|
Date/time types | ||||||||||
DATE | Yes | date + time | Yes | Yes | Yes | TEXT or INT | SQL-92 | INT (yyyymmdd) | ||
DATETIME | Yes | No | No | Yes | No | TEXT or INT | INT (unix timestamp) | |||
TIME | Yes | No | Yes | Yes | Yes | TEXT or INT | SQL-92 | INT (hhmmss) | ||
TIMESTAMP | Yes | Yes | Yes | No | Yes | TEXT or INT | SQL-92 | INT (unix timestamp) | ||
Binary data | ||||||||||
BLOB | max 65535 | Yes | No | No | max 2GB | Yes | Sybase | Microsoft Access | VARCHAR(4000) insert to_base64(val); select from_base64(col) |
|
BYTEA | No | No | Up to 1GB | No | No | BLOB | Microsoft Access | VARCHAR(4000) insert to_base64(val); select from_base64(col) |
||
BINARY(32) | max 255 | No | No | max 8000 | max 255 | BLOB | Sybase: max 32767 | Microsoft Access | SQL:2008 | CHAR(64) insert hex(val); select unhex(col) |
VARBINARY(3000) | max 65535 | No | No | max 8000 | max 32704 | BLOB | Sybase: max 32767 | Microsoft Access | VARCHAR(4000) insert to_base64(val); select from_base64(col) |
|
Other binary data | ||||||||||
CLOB | No | Yes | No | No | max 2GB | BLOB | VARCHAR(4000) | |||
IMAGE | ? | ? | ? | Deprecated | ? | BLOB | VARCHAR(4000) insert to_base64(val); select from_base64(col) |
|||
Boolean types | ||||||||||
BOOLEAN | TINYINT | No | Yes | BIT | Yes | INT | SQL:1999 | CHAR(1) | ||
BIT(8) | max 64 | ? | Yes | boolean value | ? | TEXT | CUBRID | CHAR(8) | ||
BIT VARYING(8) | No | ? | Yes | No | ? | TEXT | VARCHAR(8) | |||
Other character types | ||||||||||
NCHAR(255) | No | ? | ? | Yes | ? | unlimited TEXT | CHAR(255) | |||
NTEXT | No | ? | ? | Deprecated | ? | TEXT | VARCHAR(4000) | |||
NVARCHAR(126) | No | ? | ? | Yes | ? | unlimited TEXT | Informix: max 255 | VARCHAR(126) | ||
LVARCHAR(126) | ? | ? | ? | ? | ? | unlimited TEXT | Informix: max 32739 | VARCHAR(126) | ||
TEXT | Yes | No | Yes | ? | ? | Yes | VARCHAR(4000) | |||
NATIONAL CHARACTER(255) | No | ? | ? | Yes | ? | unlimited TEXT | SQL-92 | CHAR(255) | ||
NATIONAL CHARACTER VARYING(126) | No | ? | ? | Yes | ? | unlimited TEXT | SQL-92 | VARCHAR(126) | ||
Other decimal types | ||||||||||
FLOAT | single-precision (4 bytes) | FLOAT(126) | DOUBLE PRECISION | FLOAT(53) | double-precision | REAL or TEXT | Microsoft Access | SQL-92 | FLOAT(53) | |
REAL | DOUBLE PRECISION | FLOAT(63) | 6 digits (4 bytes) | FLOAT(24) | single-precision | REAL or TEXT | Microsoft Access | Informix | SQL-92 | FLOAT(24) |
DEC(9,2) | Yes | No | No | Yes | Yes | REAL or TEXT | DECIMAL(9,2) | |||
DOUBLE | Yes | No | No | No | Yes | REAL or TEXT | Informix | Microsoft Access | DOUBLE PRECISION | |
Other integer types | ||||||||||
BIGINT | Yes | NUMBER(19) | Yes | Yes | Yes | INT or TEXT | Firebird & Interbase | Sybase Informix CUBRID | SQL:2003 | DECIMAL(19,0) |
MEDIUMINT | Yes | No | No | No | No | INT or TEXT | Microsoft Access & Firebird | Sybase & CUBRID | INT | |
TINYINT | Yes | No | No | unsigned | No | INT or TEXT | Sybase (signed) | Firebird & CUBRID | SQL-92 | SMALLINT |
SERIAL | ? | No | Yes | ? | ? | INT or TEXT | Informix |
Notes
- SQLite accepts anything as column type because each value are dynamically typed
- Date literals can have different format across database systems
- PostgreSQL needs only 1 byte of overhead to store short string up to VARCHAR(126)
- MySQL and MariaDB need only 1 byte of overhead to store string up to VARCHAR(255)
- DECIMAL or NUMERIC type with precision greater than 9 require more storage
- Always use single quote for string literal (never use double quotes)
Reference manuals
SQL standard publications