Preloader

SQL Data Types Explained with Examples

SQL
SQL Tutorials

SQL data types tell the database what kind of data a column can store. They control how values are saved and processed. As a result, choosing the right data type keeps your database fast and reliable.

What Are SQL Data Types

SQL data types specify the type of value that a column must hold.
In a table each column has one data type.

However, names are a text data type. For example,
In addition, ages and prices are both defined to be numeric types.

Numeric Data Types

Numeric data types only store numbers.
With this in mind, they are preferable for counts, prices and totals.

Data TypeExampleUse
INT25Whole numbers
BIGINT9876543210Large numbers
DECIMAL(5,2)99.50Exact decimals
FLOAT12.75Approximate decimals

Example

CREATE TABLE products (
  id INT,
  price DECIMAL(6,2),
  stock INT
);

String Data Types

String data types hold text values.
You will generally use them for names, emails, titles.

Data TypeExampleUse
CHAR(5)HelloFixed length text
VARCHAR(50)Rahul VermaVariable length text
TEXTLong descriptionLarge text

Example

CREATE TABLE users (
  name VARCHAR(30),
  email VARCHAR(50),
  bio TEXT
);

Date and Time Data Types

The data types for date and time store values derived from a time based representation.
So they are suitable for dates, timestamps, and schedules.

Data TypeExampleUse
DATE2026-01-20Date only
TIME10:30:00Time only
DATETIME2026-01-20 10:30:00Date and time
TIMESTAMP2026-01-20 10:30:00Tracks time

Example

CREATE TABLE orders (
  id INT,
  order_date DATE,
  order_time TIME
);

Boolean Data Type

The data type booleans are used to hold empty or true values.
Thus they are exactly perfect for a yes or no type fields.

Data TypeExampleUse
BOOLEANTRUEYes or no

Example

CREATE TABLE tasks (
  title VARCHAR(50),
  completed BOOLEAN
);

How to Choose the Right SQL Data Type

First, choose the data type that matches the data that you want to store.
Secondly, use numbers for counts and totals.
Next, require text for names and descriptions.
Lastly use date types for all other time relevant values.

Helps you to keep your database simple and manageable.

Summary

SQL datatypes determine how data is stored in a table.
As they prevent invalid values, they lead to fewer errors.
Learning SQL data types, then writing queries becomes easier.

Check out our resources!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *