SQL Data Types

SQL Tutorial

Here is a clear, practical, and complete guide to SQL Data Types, covering all major database engines (MySQL, PostgreSQL, SQL Server, Oracle) with examples and best practices.

 What Are SQL Data Types?

SQL data types define what kind of values a column can store, such as:

  • Numbers

  • Text

  • Dates & times

  • Binary data

  • Boolean values

  • JSON

  • Special types (UUID, arrays, spatial, etc.)

Choosing the correct data type is critical for:

  • Performance

  • Storage efficiency

  • Validation

  • Indexing

  • Data consistency


 1. Numeric Data Types

Integer Types

TypeDescriptionMySQLPostgreSQLSQL ServerOracle
TINYINTVery small integerYesNo (as smallint)No
SMALLINTSmall integerYesYesYesYes
INT / INTEGERStandard integerYesYesYesYes
BIGINTVery large integerYesYesYesYes

Example:

age INT;

Decimal / Floating Types

TypeDescription
DECIMAL(p,s)Exact value, great for money
NUMERIC(p,s)Same as DECIMAL
FLOATApproximate values
DOUBLELarger approximate values

Example:


 2. Character (Text) Data Types

TypeDescription
CHAR(n)Fixed-length text
VARCHAR(n)Variable-length text
TEXTLong text
MEDIUMTEXT / LONGTEXT (MySQL)Very long documents

Example:


 3. Date and Time Data Types

TypeDescription
DATEYYYY-MM-DD
TIMEHH:MM:SS
DATETIMEDate + time
TIMESTAMPUTC-based, auto-update options
INTERVAL (PostgreSQL)Time spans

Examples:


 4. Boolean Data

DBBoolean Type
MySQLTINYINT(1) (TRUE=1, FALSE=0)
PostgreSQLBOOLEAN
SQL ServerBIT
OracleNo BOOLEAN in tables; use NUMBER(1)

Example:


 5. Binary Data Types

TypeDescription
BLOBBinary Large Object
VARBINARYVariable-length binary
BYTEA (PostgreSQL)Binary data
RAW (Oracle)Raw binary

Example:


 6. JSON Data Types

DBJSON Support
MySQLJSON
PostgreSQLJSON, JSONB (binary optimized)
SQL ServerStores JSON in NVARCHAR but has JSON functions
OracleJSON data type (21c+)

Example:

metadata JSON;

PostgreSQL example:

details JSONB;

 7. UUID / GUID Types

DBType
PostgreSQLUUID
MySQLCHAR(36) or BINARY(16)
SQL ServerUNIQUEIDENTIFIER
OracleRAW(16)

Example:


8. Spatial / Geographic Types

Useful for GIS applications.

DBExample Types
MySQLPOINT, POLYGON
PostgreSQL (PostGIS)geometry, geography
SQL ServerGEOMETRY, GEOGRAPHY
OracleSDO_GEOMETRY

Example:

location POINT;

 9. Array Types (PostgreSQL Only)

PostgreSQL supports arrays natively:

tags TEXT[];
scores INT[];

 10. XML Data Types

  • SQL Server: XML

  • PostgreSQL: xml

  • Oracle: XMLTYPE

Example:

config XML;

Full Example Table With Data Types


 How to Choose the Best Data Type

  •  Choose smallest type that fits the use case
  •  Prefer INT over BIGINT unless needed
  •  Always use DECIMAL for money
  •  Use VARCHAR instead of TEXT when size is known
  •  Use TIMESTAMP for time data ✔ For globally unique IDs → use UUID
  •  Avoid storing large files in DB → use object storage

Data Type Differences Across Engines (Quick Summary)

FeatureMySQLPostgreSQLSQL ServerOracle
BooleanTINYINT(1)BOOLEANBITNUMBER(1)
JSONYesJSON + JSONBYes (text-based)Yes
UUIDvia CHAR/BINARYNative UUIDUNIQUEIDENTIFIERRAW(16)
ArraysNoYesNoNo
Full GISMedium PostGISMediumStrong

You may also like...