Skip to content

Instantly share code, notes, and snippets.

@vasuadari
Created August 23, 2024 13:03
Show Gist options
  • Save vasuadari/e2c98e2b34769c00b44844ea4c5d6af7 to your computer and use it in GitHub Desktop.
Save vasuadari/e2c98e2b34769c00b44844ea4c5d6af7 to your computer and use it in GitHub Desktop.

Here’s a quick cheat sheet for common data types and their storage sizes across popular relational databases (like MySQL, PostgreSQL, and SQL Server). Keep in mind that the sizes listed are typical, but some nuances or variations might apply based on specific DBMS configurations.

Numeric Data Types

Data Type Description Storage Size (in bytes)
TINYINT Integer between -128 and 127 (signed) 1
SMALLINT Integer between -32,768 and 32,767 (signed) 2
MEDIUMINT Integer between -8,388,608 and 8,388,607 3
INT/INTEGER Integer between -2,147,483,648 and 2,147,483,647 4
BIGINT Large integer between -9 quintillion to +9 quintillion 8
FLOAT Single-precision floating-point number 4
DOUBLE Double-precision floating-point number 8
DECIMAL(p, s) Fixed-point number (precision p, scale s) Varies (Depends on p and s)

Character Data Types

Data Type Description Storage Size (in bytes)
CHAR(n) Fixed-length string (n characters) n
VARCHAR(n) Variable-length string (up to n characters) n + 1 (up to 255 bytes)
TEXT Large variable-length string Varies (up to 65,535 bytes)
MEDIUMTEXT Larger variable-length string Varies (up to 16,777,215 bytes)
LONGTEXT Very large variable-length string Varies (up to 4 GB)

Date and Time Data Types

Data Type Description Storage Size (in bytes)
DATE Stores date in YYYY-MM-DD format 3
DATETIME Stores date and time in YYYY-MM-DD HH:MM:SS format 8
TIMESTAMP Stores Unix epoch timestamp 4
TIME Stores time in HH:MM:SS format 3
YEAR Stores a year in YYYY format 1

Binary Data Types

Data Type Description Storage Size (in bytes)
BINARY(n) Fixed-length binary data n
VARBINARY(n) Variable-length binary data n + 1
BLOB Binary large object Varies (up to 65,535 bytes)
MEDIUMBLOB Larger binary large object Varies (up to 16,777,215 bytes)
LONGBLOB Very large binary large object Varies (up to 4 GB)

Other Data Types

Data Type Description Storage Size (in bytes)
BOOLEAN True or false value 1
ENUM Enumerated list of values 1 or 2 (depending on the number of values)
SET A set of values 1 to 8

This cheatsheet provides a general idea of storage sizes. Actual sizes may vary based on database configurations or specific implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment