Data Definition Language (DDL)
DDL statements create, modify, and delete database structures (tables, indexes, views).
CREATE TABLE
ALTER TABLE
DROP TABLE
Data Types
SQL supports various data types to store different kinds of information.
CHAR(n) โ Text, fixed length
TEXT โ Unlimited text
INTEGER / INT โ Whole numbers
SMALLINT โ Smaller whole numbers
BIGINT โ Larger whole numbers
DECIMAL(m,n) โ Exact decimal, m total digits, n after decimal
NUMERIC โ Alias for DECIMAL
FLOAT / REAL โ Approximate decimal
BOOLEAN โ TRUE / FALSE
DATE โ YYYY-MM-DD
TIMESTAMP โ Date and time
TIME โ Time only
SERIAL โ Auto-incrementing integer
JSONB โ JSON (PostgreSQL)
UUID โ Unique identifier (PostgreSQL)
Constraints
Constraints enforce rules on data to maintain integrity.
Common Constraints
Constraint Types
- PRIMARY KEY โ Uniquely identifies each row (NOT NULL + UNIQUE)
- FOREIGN KEY โ Links to another table's primary key
- NOT NULL โ Column must have a value
- UNIQUE โ All values in column must be different
- CHECK โ Custom condition must be true
- DEFAULT โ Default value if none provided
Data Manipulation Language (DML)
DML statements insert, update, and delete data.
INSERT
UPDATE
DELETE
UPSERT (ON CONFLICT)
SELECT & Filtering
Query data with filtering, sorting, and limiting.
Basic SELECT
WHERE Clause
ORDER BY & LIMIT
DISTINCT
Filtering Operators
Advanced filtering with operators and conditions.