SQL Tutorial

SQL Introduction SQL Aggregate Functions SQL Aliases SQL And SQL Any All SQL Avg SQL Between SQL Case SQL Comments SQL Count SQL Delete SQL Distinct SQL Exists SQL GROUP BY SQL Having SQL In SQL INSERT INTO SQL Is Not Null SQL Join SQL Full Outer Join SQL Inner Join SQL Left Join SQL Right Join SQL Self Join SQL Like SQL Min Max SQL NOT Operator SQL Null SQL Operators SQL OR operator SQL ORDER BY SQL Select SQL Select Into SQL Top Limit Fetch SQL Stored Procedures SQL Sum SQL Union SQL Update SQL Where SQL Wildcards

SQL Database

SQL Alter Table SQL Auto increment SQL Backup Database SQL Check SQL Constraints SQL Create View SQL Create Database SQL Create Table SQL Data types SQL Dates SQL Default Constraint SQL Drop Database SQL Drop Table SQL Foreign Key SQL Hosting SQL Index SQL injections SQL Not NULL SQL PrimaryKey SQL Unique SQL Views

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

CategoryExamplesUsed for
TextCHAR, VARCHAR, TEXTNames, emails, descriptions
NumbersINT, DECIMAL, FLOATQuantities, prices, measurements
Date and timeDATE, TIME, TIMESTAMPEvents, deadlines, audit records
BooleanBOOLEAN, BITTrue/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

Related topics

Continue with SQL CREATE TABLE, SQL NOT NULL, SQL Primary Key and SQL Dates.