# Database schema

> The blueprint of a database: which tables exist, their columns and how they connect.

- Level: Intermediate
- Topics: Data
- URL: https://tidbit.legios.com.ar/database-schema/
- In Spanish: [Esquema de base de datos](https://tidbit.legios.com.ar/es/database-schema/)

A **database schema** is the description of how a database is organized: which tables it has, which columns each table has, what type of value goes in each column (a number, a date, some text), which columns are required, and how tables relate to each other. It describes the shape of the data, not the data itself.

Take an online shop. The schema might say there is a `customers` table with an `id`, a `name` and an `email` that cannot be empty, and an `orders` table with an `id`, a `customer_id`, a `total` with two decimals and a `created_at` date. With that in place, the database refuses an order with a total of "banana" or with no customer. In SQL, the schema is written with commands like `CREATE TABLE` and changed with `ALTER TABLE`.

Schemas change as products change, and that is delicate: renaming a column can break every report and app that reads it. Teams handle this with **migrations**, small versioned scripts that change the schema step by step and can be reviewed like code. The word also has a narrower meaning in some databases, such as PostgreSQL, where a schema is a named folder that groups tables.

## An analogy

The blueprint of a building: it does not tell you who lives there, but it says how many rooms there are, how big each one is and which doors connect them. You cannot put a fridge where the plan says there is a staircase.

## Keep in mind

- Defines tables, columns, data types, required fields and relationships.
- Lets the database reject data with the wrong shape.
- Written and changed in SQL, ideally through versioned migrations.
- A warehouse checks the schema on write; a data lake applies it on read.

## Go deeper

- [Database schema on Wikipedia](https://en.wikipedia.org/wiki/Database_schema)
- [What is a database schema? (IBM)](https://www.ibm.com/think/topics/database-schema)

## Related terms

- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [SQL](https://tidbit.legios.com.ar/sql/): The language you use to ask a database questions.
- [Data lake](https://tidbit.legios.com.ar/data-lake/): Cheap storage where all your data is kept as raw files, to be sorted out later.
