๐Ÿงพ SQL Data Types: INT, VARCHAR, DATE, BOOLEAN, and More Explained

When working with databases, itโ€™s crucial to store data in the right format. This is where data types in SQL come in. Every column in a SQL table must have a defined data type so that the database knows how to store, validate, and retrieve values.

In this guide, weโ€™ll break down the most commonly used data types in SQL โ€” such as INT, VARCHAR, DATE, and BOOLEAN โ€” with practical examples and use cases. Whether youโ€™re a student, a developer, or just getting started with SQL, this article is for you.


๐Ÿ“ฆ What Are SQL Data Types?

SQL data types define the type of data that can be stored in a column of a table. Choosing the correct data type:

  • Ensures data integrity
  • Saves storage space
  • Improves query performance

Each SQL database (like MySQL, PostgreSQL, or SQL Server) might have slight variations, but the core data types are mostly consistent across all platforms.


๐Ÿ“‹ Common Categories of SQL Data Types

SQL data types can be grouped into several broad categories:

  1. Numeric Data Types
  2. Character/String Data Types
  3. Date and Time Data Types
  4. Boolean Data Type
  5. Other/Miscellaneous Types (e.g., BLOB, JSON, ENUM)

Letโ€™s look at each of them in detail.


๐Ÿ”ข 1. Numeric Data Types

Used to store numbers โ€” both integers and floating points.

โœ… INT (Integer)

  • Stores whole numbers (positive or negative)
  • Example: 1, -10, 200
CREATE TABLE Products (
ProductID INT PRIMARY KEY,
Price INT
);

โœ… SMALLINT, BIGINT

  • SMALLINT uses less storage (typically 2 bytes)
  • BIGINT is for very large numbers (up to 8 bytes)

โœ… DECIMAL(p, s) or NUMERIC(p, s)

  • Used for fixed-point numbers (perfect for financial data)
  • p = precision (total digits), s = scale (digits after decimal)
Salary DECIMAL(10, 2) -- Max 10 digits, 2 after the decimal

โœ… FLOAT and REAL

  • Used for floating-point (approximate) numbers
  • Less precise than DECIMAL

Note: Use DECIMAL for exact calculations (e.g., money), and FLOAT when approximation is acceptable (e.g., scientific data).


๐Ÿ“ 2. Character/String Data Types

Used to store text, characters, and strings.

โœ… VARCHAR(n)

  • Variable-length character string with a max length n
  • Efficient for most text fields like names, emails
Name VARCHAR(100),
Email VARCHAR(150)

โœ… CHAR(n)

  • Fixed-length string (always reserves n characters)
  • Faster but less flexible than VARCHAR
Code CHAR(3) -- Stores exactly 3 characters like "USA"

โœ… TEXT

  • Used for long text like comments, descriptions
  • Cannot be indexed or sorted easily in some databases
Description TEXT

๐Ÿ“… 3. Date and Time Data Types

Used for storing dates, times, or both.

โœ… DATE

  • Stores calendar dates in YYYY-MM-DD format
JoinDate DATE

โœ… TIME

  • Stores time of day in HH:MM:SS format
LoginTime TIME

โœ… DATETIME or TIMESTAMP

  • Stores both date and time (e.g., 2025-04-07 14:30:00)
  • TIMESTAMP can auto-update in some systems
CreatedAt DATETIME

โœ… 4. Boolean Data Type

Used to store true or false values.

โœ… BOOLEAN or BOOL

  • Stores TRUE or FALSE (some systems use 1 and 0)
  • Great for status fields, flags, toggles
IsActive BOOLEAN

Note: Some SQL engines like MySQL store BOOLEAN as a tiny integer (TINYINT(1)).


๐Ÿงฉ 5. Other Useful Data Types

โœ… ENUM

  • A list of predefined values. Great for fixed options like status, gender, etc.
Status ENUM('Pending', 'Shipped', 'Cancelled')

โœ… BLOB (Binary Large Object)

  • Stores binary data like images, videos, or files
ProfilePic BLOB

โœ… JSON

  • Stores structured JSON data (supported in PostgreSQL, MySQL 5.7+)
Details JSON

๐Ÿ“Š Choosing the Right Data Type: Best Practices

Data to StoreRecommended Type
IDs, countsINT, BIGINT
Money, pricesDECIMAL
Names, emailsVARCHAR
TimestampsDATETIME
Yes/No flagsBOOLEAN
CategoriesENUM
Long textTEXT
Files/imagesBLOB

โŒ Common Mistakes to Avoid

  • Using TEXT when VARCHAR is enough โ€“ wastes space
  • Using FLOAT for money โ€“ can cause rounding errors
  • Choosing CHAR instead of VARCHAR unnecessarily
  • Forgetting to define max length in VARCHAR(n)
  • Ignoring time zone differences in DATETIME or TIMESTAMP

๐Ÿ“š Real-World Example: User Table

CREATE TABLE Users (
UserID INT PRIMARY KEY,
Username VARCHAR(50) NOT NULL,
Email VARCHAR(100) UNIQUE,
JoinDate DATE DEFAULT CURRENT_DATE,
IsVerified BOOLEAN DEFAULT FALSE,
Bio TEXT
);

This table uses a variety of data types for:

  • Identifiers (INT)
  • Text fields (VARCHAR, TEXT)
  • Dates (DATE)
  • Flags (BOOLEAN)

๐Ÿง  Quick Recap Table

Data TypeDescriptionExample
INTWhole numbers1, 42, -10
VARCHAR(n)Variable-length textโ€™Johnโ€™, โ€˜abc@exampleโ€™
CHAR(n)Fixed-length textโ€™USAโ€™
DATECalendar dateโ€™2025-04-07โ€™
DATETIMEDate and timeโ€™2025-04-07 14:30:00โ€™
BOOLEANTrue or falseTRUE, FALSE
DECIMALExact decimal number99.99
ENUMFixed set of valuesโ€™Pendingโ€™
BLOBBinary data (images, files)Binary content
JSONStructured key-value data{โ€œageโ€:25, โ€œcityโ€:โ€œNYโ€}

๐Ÿ Conclusion

SQL data types are more than just labels โ€” they define how your data behaves, how much space it takes, and how efficiently it can be queried. Whether youโ€™re building a simple app or a massive enterprise system, choosing the right data types ensures performance, reliability, and data integrity.

Always keep in mind the nature of your data, how youโ€™ll use it, and what constraints it requires. As your skills grow, mastering data types will help you become a confident and effective database designer.