🚀 Day 6: Data types in SQL

3 min read
What Are Data Types?
Each column must be assigned a data type, such as:
Data Type | Description | Usage Example in a Table |
CHAR | string(0-255), can store characters of fixed length. Eg: Alice, all 50 is reserved here. Extra memory is wasted after storing ‘Alice’ | CHAR(50) |
VARCHAR(n) | string (0-255), can store characters up to given length. | VARCHAR(50) |
BLOB | string (0-65535), can store binary large object. | BLOB(1000) |
INT | Standard integer (usually 4 bytes). Can store whole numbers. | age INT, salary INT |
TINYINT | Very small integer (1 byte). Range: 0 to 255 (unsigned) or -128 to 127 (signed). | is_active TINYINT → use as boolean (0 or 1) |
BIGINT | Large integer (8 bytes). Use for values exceeding INT range. | user_id BIGINT for large ID systems |
BIT(n) | Stores n bits (1s and 0s). Common for flags or binary data. | flags BIT(4) → stores 4-bit binary value |
FLOAT | Decimal number, with precision to 23 digits. | temperature FLOAT |
DOUBLE | Decimal number, with precision to 24 - 53 digits. | account_balance DOUBLE |
BOOLEAN | Boolean values 0 or 1. | BOOLEAN |
DATE | Stores a calendar date (YYYY-MM-DD) ranging from 1000-01-01 to 9999-12-31 | birth_date DATE |
YEAR | Stores only the year (e.g., 2023). Range: 1901 to 2155 | enrollment_year YEAR |
What Are SIGNED and UNSIGNED Data Types in SQL?
In SQL (especially in MySQL), numeric data types like INT, TINYINT, BIGINT, etc., can be either:
SIGNED – can store both positive and negative numbers
UNSIGNED – can store only positive numbers (and zero), but with a larger positive range
By default, numeric types are SIGNED unless you explicitly declare them as UNSIGNED.
Data Type | Signed Range | Unsigned Range |
TINYINT | -128 to 127 | 0 to 255 |
SMALLINT | -32,768 to 32,767 | 0 to 65,535 |
MEDIUMINT | -8,388,608 to 8,388,607 | 0 to 16,777,215 |
INT | -2.14B to 2.14B | 0 to 4.29B |
BIGINT | -9.2 quintillion to +9.2 | 0 to 18.4 quintillion |
When to Use UNSIGNED?
Use UNSIGNED when:
Negative numbers don’t make sense for your column.
You want more positive range.
Term | Stores | Use When… |
SIGNED | Positive & negative | You expect negative values (e.g., temperature, balance) |
UNSIGNED | Only positive (more range) | IDs, counters, quantities, prices, etc. |
0
Subscribe to my newsletter
Read articles from Rishitha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
