🚀 Day 6: Data types in SQL

RishithaRishitha
3 min read

What Are Data Types?

Each column must be assigned a data type, such as:

Data TypeDescriptionUsage Example in a Table
CHARstring(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)
BLOBstring (0-65535), can store binary large object.BLOB(1000)
INTStandard integer (usually 4 bytes). Can store whole numbers.age INT, salary INT
TINYINTVery small integer (1 byte). Range: 0 to 255 (unsigned) or -128 to 127 (signed).is_active TINYINT → use as boolean (0 or 1)
BIGINTLarge 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
FLOATDecimal number, with precision to 23 digits.temperature FLOAT
DOUBLEDecimal number, with precision to 24 - 53 digits.account_balance DOUBLE
BOOLEANBoolean values 0 or 1.BOOLEAN
DATEStores a calendar date (YYYY-MM-DD) ranging from 1000-01-01 to 9999-12-31birth_date DATE
YEARStores only the year (e.g., 2023). Range: 1901 to 2155enrollment_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 TypeSigned RangeUnsigned Range
TINYINT-128 to 1270 to 255
SMALLINT-32,768 to 32,7670 to 65,535
MEDIUMINT-8,388,608 to 8,388,6070 to 16,777,215
INT-2.14B to 2.14B0 to 4.29B
BIGINT-9.2 quintillion to +9.20 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.

TermStoresUse When…
SIGNEDPositive & negativeYou expect negative values (e.g., temperature, balance)
UNSIGNEDOnly 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

Rishitha
Rishitha