Academic Block

SQL DATA TYPES Get Certified

Learn about SQL data types and how SQLite stores numbers, text, dates, binary data and other values using its five storage classes.

What are SQL Data Types?

Data types define the kind of value that can be stored in a database column. Different database systems provide different type systems. SQLite uses a flexible model based mainly on five storage classes: NULL, INTEGER, REAL, TEXT and BLOB.

SQLite Storage Classes

Storage Class
Description
Example
NULL
Missing or unknown value
NULL
INTEGER
Whole numbers
42
REAL
Floating-point numbers
19.95
TEXT
Character strings
‘Delhi’
BLOB
Binary data
Binary file content

INTEGER

The INTEGER storage class holds whole numbers. It is commonly used for IDs, quantities, ages, counts and similar values.

What this code does: Creates an inventory table and stores whole-number quantities.

DROP TABLE IF EXISTS inventory;
CREATE TABLE inventory (
  item_id INTEGER,
  item_name TEXT,
  quantity INTEGER
);
INSERT INTO inventory (item_id, item_name, quantity) VALUES
  (101, 'Keyboard', 15),
  (102, 'Mouse', 28),
  (103, 'Monitor', 7);
SELECT *
FROM inventory
ORDER BY item_id;

REAL

The REAL storage class holds floating-point numbers. It is useful for prices, measurements, percentages and averages.

What this code does: Stores product prices and ratings as REAL values.

DROP TABLE IF EXISTS products;
CREATE TABLE products (
  product_name TEXT,
  price REAL,
  rating REAL
);
INSERT INTO products (product_name, price, rating) VALUES
  ('Desk Lamp', 1299.50, 4.5),
  ('USB Hub', 749.99, 4.2),
  ('Laptop Stand', 1899.75, 4.7);
SELECT *
FROM products
ORDER BY price;

TEXT

The TEXT storage class holds character strings. Names, addresses, descriptions, categories and email addresses are typical examples.

What this code does: Stores customer names and cities as TEXT and filters by city.

DROP TABLE IF EXISTS customers;
CREATE TABLE customers (
  customer_id INTEGER,
  customer_name TEXT,
  city TEXT
);
INSERT INTO customers (customer_id, customer_name, city) VALUES
  (1, 'Anaya', 'Delhi'),
  (2, 'Vihaan', 'Pune'),
  (3, 'Myra', 'Bengaluru');
SELECT customer_name, city
FROM customers
WHERE city = 'Delhi';

NULL

NULL represents a missing, unknown or unavailable value. It is different from zero, an empty string, or the text value ‘NULL’.

What this code does: Shows how to find rows that contain a NULL phone number.

DROP TABLE IF EXISTS employees;
CREATE TABLE employees (
  employee_id INTEGER,
  employee_name TEXT,
  phone TEXT
);
INSERT INTO employees (employee_id, employee_name, phone) VALUES
  (1, 'Riya', '9876543210'),
  (2, 'Dev', NULL),
  (3, 'Tara', '9123456780');
SELECT employee_name, phone
FROM employees
WHERE phone IS NULL;

BLOB

BLOB (Binary Large Object) stores binary data such as images, documents or other files. Small BLOB values can be written with hexadecimal literals for testing.

What this code does: Inserts two small BLOB values and inspects their type and length.

DROP TABLE IF EXISTS files;
CREATE TABLE files (
  file_id INTEGER,
  file_name TEXT,
  file_data BLOB
);
INSERT INTO files (file_id, file_name, file_data) VALUES
  (1, 'sample.bin', X'48656C6C6F'),
  (2, 'data.bin', X'53514C');
SELECT
  file_id,
  file_name,
  typeof(file_data) AS data_type,
  length(file_data) AS size_bytes
FROM files
ORDER BY file_id;

Using typeof()

The typeof() function returns the storage class of any value.

SELECT
  typeof(25) AS integer_value,
  typeof(25.75) AS real_value,
  typeof('Hello SQL') AS text_value,
  typeof(NULL) AS null_value,
  typeof(X'414243') AS blob_value;

Boolean Values in SQLite

SQLite has no separate Boolean storage class. Boolean values are normally stored as integers: 0 for false and 1 for true.

What this code does: Stores completion status as 0/1 and converts it to readable Yes/No text.

DROP TABLE IF EXISTS tasks;
CREATE TABLE tasks (
  task_id INTEGER,
  task_name TEXT,
  completed INTEGER
);
INSERT INTO tasks (task_id, task_name, completed) VALUES
  (1, 'Read documentation', 1),
  (2, 'Practice SQL', 0),
  (3, 'Build database', 1);
SELECT
  task_name,
  completed,
  CASE
    WHEN completed = 1 THEN 'Yes'
    ELSE 'No'
  END AS is_completed
FROM tasks
ORDER BY task_id;

Date and Time Values

SQLite has no dedicated DATE or DATETIME storage class. Dates and times are commonly stored as TEXT (ISO format), REAL or INTEGER.

What this code does: Stores event dates as TEXT in YYYY-MM-DD format and filters future events.

DROP TABLE IF EXISTS events;
CREATE TABLE events (
  event_id INTEGER,
  event_name TEXT,
  event_date TEXT
);
INSERT INTO events (event_id, event_name, event_date) VALUES
  (1, 'SQL Workshop', '2026-08-27'),
  (2, 'Database Seminar', '2026-09-05'),
  (3, 'Technology Meetup', '2026-09-12');
SELECT
  event_name,
  event_date
FROM events
WHERE event_date >= '2026-09-01'
ORDER BY event_date;

Type Affinity

SQLite uses type affinity rather than strict enforcement. A column’s declared type influences how values are preferred for storage, but does not rigidly reject other types.

What this code does: Creates a REAL column and confirms the stored type with typeof().

DROP TABLE IF EXISTS measurements;
CREATE TABLE measurements (
  measurement_id INTEGER,
  description TEXT,
  value REAL
);
INSERT INTO measurements (measurement_id, description, value) VALUES
  (1, 'Temperature', 36.5),
  (2, 'Length', 12.75),
  (3, 'Weight', 68.4);
SELECT
  measurement_id,
  description,
  value,
  typeof(value) AS stored_type
FROM measurements
ORDER BY measurement_id;

Checking Different Storage Classes

What this code does: Stores several different kinds of values in one table and shows their storage classes.

DROP TABLE IF EXISTS data_samples;
CREATE TABLE data_samples (
  sample_id INTEGER,
  sample_value
);
INSERT INTO data_samples (sample_id, sample_value) VALUES
  (1, 125),
  (2, 45.75),
  (3, 'Database'),
  (4, NULL),
  (5, X'414243');
SELECT
  sample_id,
  typeof(sample_value) AS storage_class
FROM data_samples
ORDER BY sample_id;

Common SQLite Data Types Summary

Data Type / Class
Typical Use
Example
INTEGER
IDs, quantities, counts
100
REAL
Decimal measurements and values
25.75
TEXT
Names, descriptions, text dates
‘Delhi’
BLOB
Binary information
X’414243′
NULL
Missing or unknown values
NULL

Advantages of Appropriate Data Types

  • Makes table structures easier to understand.
  • Stores values in a suitable representation.
  • Simplifies queries and calculations.
  • Improves consistency when designing schemas.
  • Helps developers see the intended purpose of each column.

Best Practices

  • Choose column declarations that clearly describe the intended data.
  • Use INTEGER for whole-number values.
  • Use REAL when fractional numeric values are required.
  • Use TEXT for names, descriptions and text-based dates.
  • Use NULL only when a value can genuinely be missing or unknown.
  • Use BLOB when binary data must be stored in SQLite.
  • Remember that SQLite’s type system is more flexible than many traditional database systems.

SQLite primarily uses five storage classes: NULL, INTEGER, REAL, TEXT and BLOB. Understanding these classes helps you design tables and write queries that handle data correctly. Click Test My Code on any example to run it live, or Code Explanation to walk through the query block by block.

Ctrl + Enter to run code in the editor Esc to close the editor

🧪 Test Your SQL Code

Edit the SQL code on the left and click “Run Code” to see the result on the right.

📝 SQL Code
👁️ Preview (query result)

Click “Run Code” to see the result here.