Class 6 of 58 • SQL Fundamentals & RDBMS Core

SQL Data Types: Numeric, String, Date-Time & JSON Reference

When designing relational database tables, choosing the precise SQL Data Type for each attribute is one of the most critical decisions. Correct data types enforce domain integrity, prevent invalid inputs, optimize memory usage in the buffer pool, and accelerate index performance. In this reference guide, we examine Numeric, String, Temporal, Boolean, and Modern JSON data types.


1. Numeric Data Types

Used to store integers, floating-point decimals, and exact monetary values:

Data Type Storage Size Range & Best Use Cases
TINYINT 1 Byte -128 to 127 (or 0 to 255 unsigned). Ideal for boolean flags, age, semester numbers.
SMALLINT 2 Bytes -32,768 to 32,767. Ideal for country codes, year values, small counts.
INT / INTEGER 4 Bytes -2,147,483,648 to 2,147,483,647. The universal standard for primary keys and record counts.
BIGINT 8 Bytes -9 quintillion to +9 quintillion. Used for high-volume transactions, global IDs, timestamps.
DECIMAL(p, s) / NUMERIC Variable Exact fixed-point decimal! p = total precision, s = scale digits after dot. Essential for money (e.g., DECIMAL(10, 2) stores up to 99,999,999.99).
FLOAT / DOUBLE 4 / 8 Bytes Approximate floating-point numbers. Used for scientific measurements, GPS coordinates, physics computations.

2. String & Text Data Types

Data Type Characteristics Practical Examples & Guidelines
CHAR(M) Fixed-length string (1 to 255 characters). Trailing whitespace padded. Fixed-length codes: ISO country codes (CHAR(2) = 'IN'), PIN codes, MD5 hashes.
VARCHAR(M) Variable-length string (1 to 65,535 characters in MySQL). Names, email addresses, street names, URLs (e.g., VARCHAR(100)).
TEXT Variable-length text up to 64 KB (LONGTEXT up to 4 GB). Large articles, blog post content, comments, product descriptions.

3. Date & Time (Temporal) Data Types

Data Type Standard Format Description & Use Cases
DATE YYYY-MM-DD Stores calendar dates only: '2026-11-06'. Used for birth dates, joining dates.
TIME HH:MM:SS Stores time of day or elapsed duration: '14:30:00'.
DATETIME YYYY-MM-DD HH:MM:SS Combines date and time independent of server timezone.
TIMESTAMP YYYY-MM-DD HH:MM:SS Stores UTC epoch seconds. Automatically converts to the current session timezone. Essential for audit logs (created_at, updated_at).

4. Boolean & Modern JSON Data Types

• BOOLEAN / BOOL: Stores TRUE (1) or FALSE (0). MySQL internally implements BOOLEAN as a synonym for TINYINT(1).

• JSON: Added in modern SQL standards (MySQL 5.7+, PostgreSQL 9.4+). Validates structured JSON documents on insertion and allows indexing nested keys directly within relational queries:

-- Example: Storing and querying JSON data in SQL
CREATE TABLE customer_profiles (
    user_id INT PRIMARY KEY,
    preferences JSON
);

INSERT INTO customer_profiles VALUES
(101, '{"theme": "dark", "notifications": true, "skills": ["SQL", "Python"]}');

-- Extract JSON attribute directly
SELECT user_id, preferences->>'$.theme' AS selected_theme
FROM customer_profiles;

Next, let us learn how to document SQL scripts properly using SQL Comments!


Frequently Asked Questions (FAQ)

CHAR is a fixed-length string: CHAR(10) always occupies exactly 10 bytes on disk, padding unused space with blank spaces. VARCHAR is a variable-length string: VARCHAR(10) only uses the actual characters stored plus 1-2 prefix length bytes. Use CHAR for fixed codes (e.g., country codes like 'IN', 'US') and VARCHAR for variable names and addresses.

FLOAT and DOUBLE are approximate floating-point data types that cause binary rounding inaccuracies (e.g., 0.1 + 0.2 = 0.30000000000000004). DECIMAL (or NUMERIC) stores numbers as exact fixed-point decimals, preventing monetary calculation errors.

The international ISO 8601 standard date format across all SQL databases is 'YYYY-MM-DD' (e.g., '2026-11-06').

Next Step in Your SQL Database Learning Path:

Proceed to the next class in sequence to build production mastery of relational database architecture.

Continue to Class 7: SQL Comments → Previous: ← SQL Syntax & Rules | Full Syllabus


Related SQL Masterclass Lessons & Recommended Next Topics

SQL Syntax & Rules →

Data type declaration rules in table definition DDL.

Create Table & Data Types →

Specifying column types, lengths, and constraints.

JSON in SQL →

Modern semi-structured JSON data types and functions.

Date & Time Functions →

Manipulating DATE, DATETIME, and TIMESTAMP columns.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!