Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to SQL Notes
Topic #106

SQL Data Types — Numeric, String, Date & Boolean

Every column in a table has a data type that determines what kind of value it can hold and how it's stored, compared, and sorted.

Numeric Types

TypeUse For
INT / INTEGERWhole numbers — IDs, counts, quantities
DECIMAL(p,s) / NUMERIC(p,s)Exact values — money, precise measurements
FLOAT / DOUBLEApproximate decimal values — scientific data (avoid for money)

String Types

TypeUse For
CHAR(n)Fixed-length text — e.g. a 2-letter state code
VARCHAR(n)Variable-length text with a max length — names, emails
TEXTLong, unbounded text — articles, descriptions

Date & Time Types

TypeUse For
DATEJust a date — 2026-08-15
TIMEJust a time — 14:30:00
DATETIME / TIMESTAMPDate and time together

Boolean

MySQL doesn't have a true native BOOLEAN — it's stored as TINYINT(1) (0/1). PostgreSQL and SQL Server support a real BOOLEAN/BIT type.

Example

CREATE TABLE employees (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100),
    salary DECIMAL(10,2),
    is_active BOOLEAN,
    joined_on DATE
);

Dialect Differences

ConceptMySQLPostgreSQLSQL Server
Auto-incrementing IDAUTO_INCREMENTSERIAL / IDENTITYIDENTITY(1,1)
BooleanTINYINT(1)BOOLEANBIT
Long textTEXTTEXTVARCHAR(MAX)

Common Mistakes

  • Using FLOAT for money. Floating-point numbers can't represent values like 0.1 exactly, which causes rounding errors in financial totals — always use DECIMAL for currency.
  • Using VARCHAR(255) for everything out of habit, without thinking about the actual max length needed.
  • Storing dates as strings (e.g. VARCHAR) instead of a real DATE type — you lose the ability to sort and filter correctly.

Interview Relevance

Q: "Why shouldn't you store prices as FLOAT?" is a common one — the answer is binary floating-point representation causing rounding errors; DECIMAL stores exact values.

Practice Question

Choose an appropriate data type for: a phone number, a product price, an "in stock" flag, and a user's date of birth.

Related SQL Notes

Want to go beyond the notes?

Join CodingNow's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →