SQL Data Types
SQL data types define what kind of value a column can store. Choosing the right type helps the database validate data, store it efficiently and compare values correctly.
Common categories
| Category | Examples | Used for |
|---|---|---|
| Text | CHAR, VARCHAR, TEXT | Names, emails, descriptions |
| Numbers | INT, DECIMAL, FLOAT | Quantities, prices, measurements |
| Date and time | DATE, TIME, TIMESTAMP | Events, deadlines, audit records |
| Boolean | BOOLEAN, BIT | True/false values |
Example
CREATE TABLE products (
product_id INT PRIMARY KEY,
product_name VARCHAR(100) NOT NULL,
price DECIMAL(10, 2) NOT NULL,
created_at TIMESTAMP
);
DECIMAL(10, 2) is a better choice for money than a floating point type because it stores fixed precision values.
Choosing a type
- Use text types for text, not for numbers that need math.
- Use date/time types for dates so sorting and filtering work correctly.
- Use a numeric type with suitable precision for money and measurements.
- Check your database documentation before relying on a type name across engines.
Related topics
Continue with SQL CREATE TABLE, SQL NOT NULL, SQL Primary Key and SQL Dates.