
A database schema is the blueprint of your data: which tables exist, which columns they hold, what type each column has and how the tables relate to each other. A well-designed schema prevents contradictory data, keeps queries short and lets your application grow without painful rewrites. This guide focuses on relational databases such as PostgreSQL, MySQL and SQLite, which remain the default choice for most applications in 2026.
In 1970 the IBM researcher Edgar F. Codd published the relational model, the idea of storing data in tables of rows and columns linked by shared values instead of hard-wired pointers. He also defined normalization, a set of rules for removing duplicated data. In 1976 Peter Chen introduced the entity-relationship (ER) diagram, still the standard way to sketch a schema. SQL became an ANSI standard in 1986 and is still the language of relational databases.
Do not open a database tool first. Write down what the application must do and what questions it must answer. For an online shop, these might be: customers place orders, an order contains several products, and the owner wants monthly sales per product. Nouns in these sentences (customer, order, product) usually become tables; verbs (places, contains) become relationships. Note which queries will run most often.
An entity is a thing you store facts about; its attributes become columns. Keep each attribute atomic: one value per column. Store a customer's first and last name in separate columns if you will sort or search by them, and never put a comma-separated list of phone numbers in one field. Sketch the entities as an ER diagram on paper or in a tool such as dbdiagram.io.
Every table needs a primary key, a column whose value uniquely identifies each row and never changes. Most teams use a surrogate key: an auto-generated integer (id BIGINT GENERATED ALWAYS AS IDENTITY in PostgreSQL) or a UUID. Avoid natural keys such as email addresses or national ID numbers as primary keys: people change emails. Protect natural identifiers with a UNIQUE constraint instead.
Relationships are expressed with foreign keys, columns that point to the primary key of another table. There are three kinds:
Declare foreign keys in the database, for example REFERENCES customers(id), so it refuses an order for a customer who does not exist. Decide what happens on delete: ON DELETE CASCADE removes dependent rows, while RESTRICT blocks the deletion.
Normalization removes redundancy so that each fact is stored in exactly one place. For most applications, reaching the third normal form is enough:
Duplicated data leads to update anomalies: change an address in one row, forget another, and your data contradicts itself. Denormalize only deliberately, for measured performance reasons. Note that copying the price into order_items is not a mistake: it records the historical price at the time of sale.
Constraints are your last line of defence: application code has bugs, but the database enforces its rules for every client.
Choose one convention and stick to it, for example lowercase snake_case, plural table names and foreign keys named table_id. Add indexes on columns you filter, join or sort by often, especially foreign keys, which PostgreSQL does not index automatically. Each index speeds reads but slows writes. Check slow queries with EXPLAIN. Finally, change the schema only through versioned migrations (Flyway, Alembic, Prisma Migrate) so every environment stays in sync.
Start small, test your schema against real queries with sample data, and refine it through migrations.
Grade 10 Math: Functions and Reasoning - Quiz
1170 questions