Skip to main content

Data Types in SQL (MySQL)

This document details the main data types in SQL, organized by category, with examples and recommendations for use based on storage efficiency and purpose.


1. Numeric Types

TypeBytesDescriptionRecommendations for use
TINYINT1Very small integer (-128 to 127)Boolean flags, simple states
SMALLINT2Small integerSmall codes, low-range counters
MEDIUMINT3Medium integerIntermediate IDs, small balances
INT or INTEGER4Standard integerPrimary keys, general counters
BIGINT8Large integerRunning totals, transactions, timestamps
DECIMAL(M,D)VariableFixed decimal numberFinancial data where exact precision is required
FLOAT4Single precision floating pointApproximate metrics, quick calculations
DOUBLE8Double precision floating pointScientific calculations, complex statistics
BIT(n)NBitfield of length nCompact storage of binary flags

2. String Types

TypeBytes (approx.)DescriptionRecommendations for use
CHAR(n)nFixed length stringUniform codes, fixed keys
VARCHAR(n)n + 1Variable length stringNames, addresses, editable fields
TEXTVariableLong text up to 65,535 charactersDescriptions, free content
TINYTEXT≤ 255Small textBrief comments, tags
MEDIUMTEXT≤ 16 MBMedium textArticles, blog posts
LONGTEXT≤ 4 GBVery long textExtensive documents, detailed logs
ENUMVariableDefined list of valuesLimited states, closed categories
SETVariableMultiple set of valuesMultiple selections among known values
BINARY(n)nFixed binary dataHashes, encoded keys
VARBINARY(n)n + 1Variable binary dataFiles, small images

3. Date and Time Types

TypeBytesDescriptionRecommendations for use
DATE3Date (YYYY-MM-DD)Date of birth, events
DATETIME8Full date and timeHuman timestamps, event logs
TIMESTAMP4UNIX format Date/time (TZ auto-adjust)Audit logs, external synchronization
TIME3Time of daySchedules, specific duration
YEAR1Year (YYYY)Annual record, fiscal periods

4. Special Types

TypeBytesDescriptionRecommendations for use
JSONVariableStructured JSON objectSemi-structured data, dynamic configuration
GEOMETRYVariableSpatial coordinatesGIS systems, maps
POINT, LINESTRING, POLYGONVariableGeometrical variantsGeolocation, spatial plotting
BOOL / BOOLEAN1 (alias of TINYINT)Logical true/falseFlags, binary states

5. General Recommendations

  • Efficiency: Use TINYINT, SMALLINT or ENUM when the data set is limited.
  • Financial precision: Prefer DECIMAL over FLOAT/DOUBLE to avoid rounding errors.
  • Long text: TEXT and its variants are not directly indexable, consider VARCHAR if you need searches.
  • Timestamps: Use TIMESTAMP if you need timezone compatibility; DATETIME if you want to avoid adjustment.
  • Identifiers: For primary keys use INT UNSIGNED AUTO_INCREMENT unless cardinality demands it (BIGINT).
  • Flexibility: JSON is useful in dynamic models but more costly in operations; avoid overusing in normalized databases.