SQL Data Types – Complete Beginner’s Guide

 

 

✨ Introduction

When designing a database, the first step is deciding what type of data each column will store. SQL provides data types for numbers, text, dates, boolean values, and more. Choosing the right type ensures efficient storage, data integrity, and faster queries.

If you’re new, start with our Introduction to SQL guide before diving deeper.

1️⃣ Numeric Data Types – Storing Numbers

Numeric data types store integers and decimals.

Data Type Description Example
INT / INTEGER Whole numbers EmpID INT
SMALLINT Small-range integers Age SMALLINT
BIGINT Large integers Population BIGINT
DECIMAL / NUMERIC(p,s) Fixed-point numbers Salary DECIMAL(10,2)
FLOAT / REAL / DOUBLE Approximate floating numbers Rating FLOAT
Tip: Use DECIMAL for financial calculations to avoid rounding errors.
CREATE TABLE Employees (
    EmpID INT PRIMARY KEY,
    Salary DECIMAL(10,2),
    Rating FLOAT
);

2️⃣ String / Character Data Types – Text & More

SQL offers types to store text in fixed or variable lengths.

Data Type Description Example
CHAR(n) Fixed-length string Code CHAR(5)
VARCHAR(n) Variable-length string Name VARCHAR(50)
TEXT / CLOB Large text Description TEXT
Tip: Use VARCHAR for most text. CHAR is ideal when text length is fixed.
CREATE TABLE Customers (
    CustomerID INT PRIMARY KEY,
    FirstName VARCHAR(50),
    LastName VARCHAR(50),
    Bio TEXT
);

3️⃣ Date & Time Data Types – Track Time Efficiently

Store dates, times, or timestamps depending on your needs.

Data Type Description Example
DATE Stores date only 2025-09-10
TIME Stores time only 14:30:00
DATETIME / TIMESTAMP Stores date + time 2025-09-10 14:30:00
YEAR (MySQL) Stores year only 2025
CREATE TABLE Orders (
    OrderID INT PRIMARY KEY,
    OrderDate DATE,
    DeliveryTime TIME,
    CreatedAt DATETIME
);

Tip: Always store timestamps in UTC to avoid timezone issues. For advanced functions, check the MySQL date/time functions or SQL Server documentation.

4️⃣ Boolean & Specialized Data Types

Data Type Description Example
BOOLEAN / BIT True/False values IsActive BOOLEAN
ENUM (MySQL) Predefined list of values Status ENUM('Pending','Shipped','Delivered')
BLOB / BYTEA Binary data (images, files) ProfilePicture BLOB

5️⃣ SQL Data Types Across Databases

Feature MySQL SQL Server Oracle
Integer INT, SMALLINT, BIGINT INT, SMALLINT, BIGINT NUMBER
String CHAR, VARCHAR, TEXT CHAR, VARCHAR, NVARCHAR, TEXT CHAR, VARCHAR2, CLOB
Date/Time DATE, DATETIME, TIMESTAMP DATE, DATETIME, DATETIME2 DATE, TIMESTAMP
Boolean BOOLEAN BIT NUMBER(1)

Tip: Always check database-specific limits to avoid errors.

✅ Key Takeaways

  • Numeric → INT, DECIMAL, FLOAT
  • String → CHAR, VARCHAR, TEXT
  • Date/Time → DATE, TIME, DATETIME
  • Boolean/Special → BOOLEAN, ENUM, BLOB
  • Correct data types improve performance, storage, and accuracy.

📚 Continue Learning

💬 Got a question about SQL Data Types? Drop it in the comments below and let’s discuss!


Leave a Comment