In the previous post, we explored SQL basics and how we interact with databases.
But hereβs π
π What kind of data can we actually store in MySQL?
Thatβs where Data Types come in.
πΉ What are Data Types?
Data types define what kind of value a column can store.
Think of it like rules:
- Name β text
- Age β number
- Date β date
Without data types, data would become messy and inconsistent.
πΉ Types of Data in MySQL
MySQL mainly supports:
- π Character (String) types
- π’ Numeric types
- π Date & Time types
- πΌοΈ Binary / Large Object types
πΉ 1. Character (String) Data Types
Used to store text values π
-
CHAR(n)
- Fixed length
- Faster retrieval
- Wastes space
-
VARCHAR(n)
- Variable length
- Saves space
- Slightly slower than CHAR
π Example use cases:
- Name
- Address
- City
πΉ 2. TEXT Data Types
Used for large text data
- TINYTEXT β up to 255 characters
- TEXT β up to 65,535 characters
- MEDIUMTEXT β up to 16 MB
- LONGTEXT β up to 4 GB
π‘ Stored outside the table (uses pointer internally)
π Used for:
- Comments
- Reviews
- Resume
- Feedback
πΉ 3. Numeric Data Types
Used for numbers π
Integer Types
- TINYINT (1 byte)
- SMALLINT (2 bytes)
- MEDIUMINT (3 bytes)
- INT (4 bytes)
- BIGINT (8 bytes)
π Used for: age, count, IDs
Floating Point Types
- FLOAT β up to 7 decimal precision
- DOUBLE β up to 15 decimal precision
- DECIMAL β exact precision (used for money π°)
Boolean
- TRUE β 1
- FALSE β 0
πΉ 4. Date and Time Data Types
Used for storing date & time π
- DATE β 'YYYY-MM-DD'
- TIME β 'HH:MM:SS'
- DATETIME β date + time
- YEAR β year only
π Used for:
- DOB
- Login time
- Transactions
πΉ 5. Binary & Large Objects (BLOB)
Used for storing multimedia data π
- TINYBLOB
- BLOB
- MEDIUMBLOB
- LONGBLOB
π Used for:
- Images
- Videos
- Audio
- Files
π‘ Stored outside the table (like TEXT)
πΉ Important Concept
π Large data types (TEXT, BLOB) are:
- Stored outside the table
- Accessed using pointers
- Not ideal for searching
π‘Learning
- Use CHAR β when length is fixed
- Use VARCHAR β when length varies
- Use DECIMAL β for money
- Use TEXT/BLOB β for large data
π In the next post, weβll start writing real SQL queries (hands-on π)
Top comments (0)