CoreTrail

Schema & data changes

Define tables, enforce constraints, and modify data safely.

Chapter overview 2 min read
On this page

What rule should the database enforce?

Tables and constraints encode assumptions that query authors otherwise have to guess. Data changes introduce another question: what must happen atomically, and what happens when a write conflicts or repeats?

Decision reference

Operation Start with
Define or change structure CREATE / ALTER TABLE
Enforce identity or relationships PRIMARY KEY / UNIQUE / FOREIGN KEY
Enforce row rules NOT NULL / CHECK
Change rows INSERT / UPDATE / DELETE
Handle conflicts ON CONFLICT / MERGE; engine-specific semantics

In this chapter

Check the invariant

For every constraint or write pattern, state the rule the database is protecting. Then ask what happens on duplicate input, partial failure, or a retry.

Type a concept, keyword, or function.