In SQL (Structured Query Language) database there are various data types to determine the kind of value that can be stored in a column or field of a table. Below are the most commonly used SQL data types.
Character/String Data Types
- VARCHAR(n): Variable-length character strings where n is the number of specified character allowed. for instance
VARCHAR(150)
allows up to 150 characters). - TEXT: Stores large text data.
- NCHAR(n): Fixed-length Unicode strings.
- NVARCHAR(n): Variable-length Unicode strings.
- CLOB (Character Large Object): Stores large text data.
- CHAR(n): Fixed-length character strings where n is the fixed number of specified character allowed. for instance
VARCHAR(150)
allows 150 characters.
Numeric Data Types
- INT : Stores whole numbers example -10, 1, 50, 200.
- SMALLINT: Smaller range of whole numbers compared to INT eg -200.
- BIGINT: Larger range of whole numbers compared to INT.
- TINYINT: Very small range of whole numbers usually 0 to 255.
- DECIMAL(p, s) / NUMERIC(p, s): Fixed-point numbers with precision
p
and scales
(e.g.,DECIMAL(5, 2)
for numbers like 123.45). - FLOAT: Approximate numeric values with floating-point precision.
Date and Time Data Types
- DATE: Stores date values (e.g.,
YYYY-MM-DD
). - TIME: Stores time values (e.g.,
HH:MM:SS
). - DATETIME: Stores both date and time (e.g.,
YYYY-MM-DD HH:MM:SS
). - TIMESTAMP: Stores date and time, often used for recording events.
- YEAR: Stores a year value (e.g.,
YYYY
). - INTERVAL: Represents a span of time.
JSON Data Type
JSON: Stores JSON (JavaScript Object Notation) data.
Boolean Data Type
BOOLEAN / BOOL: Stores TRUE
or FALSE
values.
Binary Data Types
- BINARY(n): Fixed-length binary data.
- VARBINARY(n): Variable-length binary data.
- BLOB (Binary Large Object): Stores large binary data like images or files.