Schema
In one line
A schema is the blueprint of a database — it defines the tables, columns, data types, constraints, and relationships.
In simple words
A schema is the structure of a database. It defines what tables exist, what columns each table has, the data types of those columns, the constraints (primary keys, foreign keys, etc.), and the relationships between tables.
The schema is the "shape" of the data. In a relational database, the schema is fixed — every row must conform to it. This is in contrast to NoSQL databases, which are "schemaless" (each document can have different fields).
Schemas can change over time through migrations — scripts that add, remove, or modify tables and columns. Managing schema changes is a critical part of database operations.
In some databases (like PostgreSQL), "schema" also refers to a namespace within a database — a way to group related tables.
Example
-- This entire CREATE statement defines part of the schema
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);The CREATE TABLE statement defines the schema for the users table.
Related terms
Related Resources
Related Lessons
- Database Design
Learn how to design database schemas.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.