# Schema-on-Write

> The shape is fixed first. Data that does not fit is turned away.

**Field:** Data Engineering  
**Category:** Foundations  
**Also known as:** Schema on Write

## Think of it like

It is like a mailbox slot. Only letters of the right size fit through.

## Definition

Schema-on-write means the shape of the data is set before any data goes in. Each table is created with fixed columns and types. When a row is written, the database checks it against that shape. A row that does not fit is turned away. Classic databases and warehouses work this way.

## Example

A bank's payments table only takes amounts as numbers. A file with "ten pounds" in that column fails to load.

## Example code

```sql
CREATE TABLE visit (id INT, guests INT);
INSERT INTO visit VALUES (1, 'ten');
-- ERROR:  invalid input syntax for type integer: "ten"
```

PostgreSQL turns away a row that does not match the table's types.

## Why it matters

Bad data is caught at the door. Everyone who reads the table can trust its shape.

## Common mistake

Thinking it is always slower. Checking on the way in makes each read simpler and often faster.

## Three principles

- **Shape first.** Columns and types come before data.
- **Checked on write.** Each row is tested as it goes in.
- **Trusted reads.** Readers know what to expect.

## Related terms

- [Schema-on-Read](https://learn.benibix.com/term/data/schema-on-read)
- [Database Schema](https://learn.benibix.com/term/development/schema)
- [Structured Data](https://learn.benibix.com/term/data/structured-data)

## Told apart from

- [Schema-on-Write vs Schema-on-Read](https://learn.benibix.com/compare/schema-on-write-vs-schema-on-read): People think schema-on-read means data with no schema. Both have a schema. Schema-on-write checks each row against the shape when it is stored. Schema-on-read stores data as it comes and applies the shape in each query. The first catches bad data early. The second lets you load first and ask later.

## Taught in

- [Schema on Write and on Read](https://learn.benibix.com/learn/data-foundations/schema-on-write-and-schema-on-read): Data Engineering Basics, 10/11

---

Source: https://learn.benibix.com/term/data/schema-on-write
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-20
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
