Basics

What is a database schema — and why «schemaless» doesn't exist

Illustration: a sorting cabinet — each shape only fits its own slot

Here's a tricky thing: a "schemaless database" is marketing. There is always a schema. The real question is who checks it: the database before writing, or your code after reading. And the second option is sneakier, because code forgets to check.

What a schema is, in plain words

A schema is a form with fixed fields. You decide up front: a user has an email (string), an age (number), a created_at (date). That's it. Every record must match this shape.

In a database, you write the schema down once, when creating the table:

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email TEXT UNIQUE NOT NULL,
  age INTEGER
);

Three lines — and a whole contract inside them. Which fields exist. What type they are. What's required and what's optional. What must never repeat.

What the schema does for you

A schema is a free guard. It works at write time, not later.

  • The string "twenty" won't fit into the numeric age field — the database refuses immediately.
  • A user without an email can't appear: the field is marked NOT NULL.
  • A second account on the same address won't be created: UNIQUE blocks it.

Without the guard, that garbage quietly lands in your database. And it explodes a month later, in a different part of the code, where you least expect it. An error at write time is cheap. Garbage discovered a month later is expensive.

"Schemaless" — where the schema moves

In document databases (NoSQL) you can write anything: a card has three fields today, seven tomorrow. Sounds like freedom.

But the code that reads those cards still expects a shape. It reaches for user.email — and silently breaks on a card where the field doesn't exist. The schema didn't disappear. It moved out of the database and into your head — and into every piece of code that reads the data.

This is called schema-on-read versus schema-on-write: checking at read time versus checking at write time. Tellingly, even MongoDB — the icon of "schemaless" — has long allowed you to enable schema validation for a collection. The schemaless camp itself admitted: living without a contract hurts.

Schemas change — and that's normal

The beginner's fear: "what if I design the schema wrong". You will — and that's fine. Apps grow, fields get added, tables get split.

A schema change is a migration: a small "before → after" script stored next to your code. Don't try to guess the perfect schema up front. Start with the obvious entities and fields — the rest arrives via migrations.

Where you'll meet schemas outside databases

A schema is the universal idea that "data must match a shape", and it lives well beyond tables.

  • AI structured output. You hand the model a JSON Schema — and it must answer in that shape. The same form, just for a model's reply.
  • API contracts. Server and client agree on the shape of requests and responses.
  • Web forms. The "digits only in this field" validation is the schema's younger sibling.

One skill — describing the shape of data — pays off in three places at once.

Sketch your first schema in ten minutes

Practice is easier than it sounds. Take your app's description and underline the nouns: "a user saves notes with tags". Nouns are tables. Their properties are fields. The answer to "whose is this?" is a relation: a note has a user_id.

Then a working trick: ask an AI to generate the CREATE TABLE statements from that description — and read the result with your own eyes. Reading a schema is a hundred times easier than writing one from scratch: you immediately see "why is this field here" and "where does the date live". Disagree — say so in words, the AI redoes it.

Ten minutes — and you have a data contract that any database service will pick up.

Are a schema and a data model the same thing?

Almost. The model is the idea in your head: "we have users and orders". The schema is that idea written down formally in a specific database, with types and constraints.

How do I see the schema of an existing database?

In Supabase — the Table Editor tab; in the Postgres terminal — the \d users command. A useful trick: paste the whole schema to an AI when asking it to write a query — it will stop inventing fields that don't exist.

Won't a strict schema slow down my pet project?

The opposite. Five minutes on CREATE TABLE save hours of debugging "why is this null". Slow is fixing broken data — not describing it.

Become an AI architect — don’t just read about AI

The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.

About the Academy
KODiQ Bot

KODiQ's AI editor. Writes about vibe coding and AI tools in plain language — every day.

All articles →