This guide is specifically for PostgreSQL syntax.
SQL Data Types Cheat Sheet
Reference for common SQL data types across databases.
Numeric Types
Syntax:
INT | BIGINT | DECIMAL(p,s) | FLOAT | DOUBLE
Store integer and decimal numbers.
Example:
CREATE TABLE products (id INT, price DECIMAL(10,2), weight FLOAT);
💡 Note: DECIMAL for exact precision (money), FLOAT for approximate
String Types
Syntax:
CHAR(n) | VARCHAR(n) | TEXT | NVARCHAR(n)
Store text data. CHAR is fixed-length, VARCHAR is variable.
Example:
CREATE TABLE users (country_code CHAR(2), name VARCHAR(100), bio TEXT);
💡 Note: NVARCHAR for Unicode support
Date/Time Types
Syntax:
DATE | TIME | DATETIME | TIMESTAMP | TIMESTAMPTZ
Store dates and times.
Example:
CREATE TABLE events (event_date DATE, start_time TIME, created_at TIMESTAMP);
💡 Note: TIMESTAMPTZ includes timezone (PostgreSQL)
Boolean
Syntax:
BOOLEAN | BIT
Store true/false values.
Example:
CREATE TABLE users (is_active BOOLEAN DEFAULT true);
💡 Note: SQL Server uses BIT, others use BOOLEAN
JSON Types
Syntax:
JSON | JSONB
Store JSON documents. JSONB is binary and indexable.
Example:
CREATE TABLE logs (data JSONB);
💡 Note: JSONB preferred for querying (PostgreSQL)
UUID
Syntax:
UUID | UNIQUEIDENTIFIER
Store universally unique identifiers.
Example:
CREATE TABLE users (id UUID PRIMARY KEY DEFAULT gen_random_uuid());
💡 Note: UNIQUEIDENTIFIER in SQL Server
Quick Reference Table
| Function | Purpose | |----------|---------| | Numeric Types | Store integer and decimal numbers | | String Types | Store text data | | Date/Time Types | Store dates and times | | Boolean | Store true/false values | | JSON Types | Store JSON documents | | UUID | Store universally unique identifiers |
Related Cheat Sheets
Continue learning with more SQL references:
PostgreSQL-Specific Notes
This page covers PostgreSQL syntax. Other databases may have different syntax for similar operations.