Data Types in SQL: INT, VARCHAR, DATE and More
💡 Concept Name
SQL Data Types define the kind of data a column can hold—such as integers, strings, dates, or booleans. Choosing the right type improves performance and enforces proper data handling.
📘 Quick Intro
Every column in an SQL table must have a data type, determining the kind of values it can store. For example, INT
stores whole numbers, VARCHAR
stores text, and DATE
stores calendar dates. These types influence storage size, operations, and indexing.
🧠 Analogy / Short Story
Think of a filing cabinet where each drawer is labeled for a specific item—files, keys, photos, or documents. You wouldn’t store soup in a drawer for papers! Similarly, SQL data types tell the database what kind of "item" (value) belongs in each column. They help keep order and avoid confusion when storing or retrieving data.
🔧 Technical Explanation
INT
: Whole numbers (e.g., 1, -100, 42)VARCHAR(n)
: Variable-length text up to n charactersCHAR(n)
: Fixed-length text of exactly n charactersDATE
: Stores calendar dates (YYYY-MM-DD)DATETIME
: Includes both date and timeBOOLEAN
: True or false values (usually 0 or 1)FLOAT
: Approximate floating-point numbersDECIMAL(p,s)
: Exact numeric values with precision and scaleTEXT
,BLOB
: Large text or binary objects
🎯 Purpose & Use Case
- ✅ Store customer names using
VARCHAR
- ✅ Record product prices with
DECIMAL
- ✅ Save birthdates using
DATE
- ✅ Track boolean flags like isActive with
BOOLEAN
- ✅ Use
INT
for counting orders or IDs
💻 Real Code Example
CREATE TABLE Users (
UserID INT PRIMARY KEY,
Username VARCHAR(50) NOT NULL,
BirthDate DATE,
Email VARCHAR(100) UNIQUE,
IsActive BOOLEAN DEFAULT 1,
AccountBalance DECIMAL(10,2)
);

❓ Interview Q&A
Q1: What is the difference between VARCHAR and CHAR?
A: VARCHAR
is variable-length, saving space for shorter strings, while CHAR
always uses the full defined length, padding with spaces.
Q2: When should you use DECIMAL over FLOAT?
A: Use DECIMAL
for precise financial values, and FLOAT
for approximate scientific calculations.
Q3: What does a BOOLEAN store in SQL?
A: It stores TRUE or FALSE values, usually represented as 1 or 0 in many databases.
Q4: How is a DATE different from a DATETIME?
A: DATE
only stores calendar dates, while DATETIME
stores both date and time.
Q5: Can we use TEXT instead of VARCHAR?
A: TEXT is used for very large strings and doesn’t support indexing or certain functions like VARCHAR does.
Q6: What is the default size for INT?
A: Typically 4 bytes, allowing values between -2,147,483,648 to 2,147,483,647.
Q7: What is the maximum length of a VARCHAR in MySQL?
A: 65,535 bytes (depends on character set and other columns).
Q8: Is BOOLEAN a standard SQL type?
A: Not in all dialects—some emulate BOOLEAN using TINYINT(1).
Q9: Can you store time zones in DATE or DATETIME?
A: No, for that you typically use TIMESTAMP WITH TIME ZONE
in supported databases.
Q10: What type should you use to store money?
A: Use DECIMAL
or MONEY
type if your DBMS supports it.
📝 MCQs
Q1. Which type is best for storing names?
- INT
- BOOLEAN
- VARCHAR
- DATE
Q2. What does DECIMAL(10,2) mean?
- Max 10 rows
- 10 digits total, 2 decimals
- 10 decimals only
- Fixed to 2 digits
Q3. Which type stores true/false?
- VARCHAR
- BOOLEAN
- DATE
- INT
Q4. Which type is fixed-length text?
- VARCHAR
- TEXT
- CHAR
- BLOB
Q5. What is DATE used for?
- Phone numbers
- Calendar dates
- Passwords
- Table names
Q6. FLOAT stores what kind of numbers?
- Exact decimals
- Strings
- Approximate decimals
- Binary only
Q7. VARCHAR(50) means?
- 50 digits
- 50 tables
- Text up to 50 characters
- 50 bytes exactly
Q8. What type to use for monetary values?
- VARCHAR
- BOOLEAN
- FLOAT
- DECIMAL
Q9. Which type supports large text blobs?
- DATE
- INT
- TEXT
- BOOLEAN
Q10. What is stored in DATETIME?
- Only date
- Only time
- Table structure
- Date and time
💡 Bonus Insight
Choosing the right data type impacts database size, query speed, and data integrity. Always pick the narrowest type that fits your data—like using TINYINT
instead of INT
for age—or CHAR(2)
for fixed-length country codes. It makes databases more efficient and reliable.
📄 PDF Download
Need a handy summary for your notes? Download this topic as a PDF!