Design a schema from a description
Turns a domain in prose into tables, keys and the constraints that protect them.
Design a database schema for this. The domain, in my words: [DESCRIBE WHAT THE SYSTEM TRACKS] Expected scale: [ROWS PER TABLE, ROUGHLY] The queries that must be fast: [LIST THEM] Give me tables with columns and types, primary and foreign keys, the constraints that make invalid states impossible, and the indexes the listed queries need. Then, separately: - **Every place you had to guess** at a relationship being one-to-many rather than many-to-many. Those are the questions I should answer before this is built. - **What this design makes hard.** Every schema is a bet; say what it bets against. Do not add a "metadata JSON" column as a way of avoiding a decision. If something genuinely needs to be flexible, say why.
Highlighted parts are placeholders. Replace them before you send.
Worked example
The input is invented for this page. The output shows what the prompt asks for with that input.
Example input (invented)
The domain: A community tool library. Members borrow tools. Each tool is one physical item. A loan has a due date and a return date. A member can reserve a tool that is out.
Expected scale: About 400 members, 1,500 tools and 20,000 loans a year.
The queries that must be fast: Which tools are out now and who has them. One member's loan history. All overdue loans.
Example output
CREATE TABLE member (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE
);
CREATE TABLE tool (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
category TEXT NOT NULL
);
CREATE TABLE loan (
id INTEGER PRIMARY KEY,
tool_id INTEGER NOT NULL REFERENCES tool (id),
member_id INTEGER NOT NULL REFERENCES member (id),
borrowed_on DATE NOT NULL,
due_on DATE NOT NULL,
returned_on DATE,
CHECK (due_on >= borrowed_on),
CHECK (returned_on IS NULL OR returned_on >= borrowed_on)
);
-- One open loan per tool.
CREATE UNIQUE INDEX loan_open_tool ON loan (tool_id) WHERE returned_on IS NULL;
-- Overdue loans.
CREATE INDEX loan_open_due ON loan (due_on) WHERE returned_on IS NULL;
-- A member's history.
CREATE INDEX loan_member ON loan (member_id, borrowed_on);
CREATE TABLE reservation (
id INTEGER PRIMARY KEY,
tool_id INTEGER NOT NULL REFERENCES tool (id),
member_id INTEGER NOT NULL REFERENCES member (id),
reserved_at TIMESTAMP NOT NULL,
UNIQUE (tool_id, member_id)
);
The two indexes with a WHERE hold open loans only. "Out now" and "overdue" read those few rows and never the full history, which grows by 20,000 rows a year. A second open loan for the same tool fails on the unique index.
Where I guessed
- A reservation points at one physical tool. If the library owns three identical drills and members do not care which one they get, a reservation should point at a model, and
toolsplits into a model and its copies. - One loan belongs to one member. If a household shares a membership, members and memberships become many-to-many.
- A tool has one category. A tool that belongs in two needs a join table.
What this design makes hard
- A reservation is a row you delete once it is served, so there is no record of how long people waited.
- A tool is either on loan or free. A tool that is lost or away for repair looks free. That needs a status column with rules of its own.
- Someone who borrows four tools in one visit creates four separate loans. Nothing groups them for a receipt.
More Data prompts
3 of the 5 other prompts filed under Data.
Explain and fix a spreadsheet formula
Understand a formula you inherited, then repair it.
Extract structured data from messy text
Pulls fields into JSON and marks what was missing instead of inventing it.
Find the story in this data
Ask what changed and what it means — with the caveats intact.
Data tools and skills
1 tool and 3 skills are filed under Data, the same category as this prompt.
Julius AI
Chat with a spreadsheet and get analysis plus charts.
Data cleaner
Profiles a messy dataset and proposes fixes before changing anything.
Data table analyst
Reads a table and reports what changed, with the caveats left in.
Migration safety checker
Finds the database migrations that will lock a table or break running code.