Blog

Drawing ERDs with AI: Prompts and Verification

"Is there an AI that draws ER diagrams?" — there is. Give ChatGPT or Claude a description of your service and it will design a schema for you. There's just one trick to it: don't ask for a picture. Ask for DDL — CREATE TABLE statements.

This article covers why that matters, prompts that actually produce good output, how to turn the DDL you get into a diagram, and — most importantly — the defects you should expect to find in AI output, with real screenshots.

Why DDL, not a picture

Ask an AI to "draw an ERD" and you usually get one of three things: an image, Mermaid code, or a table-shaped description. All three look plausible. All three get stuck the moment you try to work with them.

An image can't be edited — changing one column means regenerating everything. Mermaid embeds nicely in docs, but its syntax can't express much about types and constraints, and turning it into a real database means writing the DDL yourself after all.

DDL changes the game. CREATE TABLE statements are an executable artifact in their own right: paste them into an ERD tool and you have a diagram, run them against a database and you have real tables. DDL is the format that lets AI output flow onward to wherever you need it.

What a good prompt looks like

Output quality tracks prompt quality closely. Vague requests get vague schemas.

I'm building a book club management service.

- Members can create reading groups and join them
- Each group picks one book per month
- Members leave a rating (1-5) and a review for books they've read

Design a MySQL schema for this.

Requirements:
- Reply with CREATE TABLE statements only
- Add a COMMENT to every table and column
- Declare FKs with explicit CONSTRAINT clauses
- Use BIGINT AUTO_INCREMENT surrogate keys for PKs

Three things are doing the work here. Requirements written as plain sentences (that's where the AI extracts entities and relationships), the output format pinned to DDL, and quality conditions made explicit: COMMENT, FK, PK. The COMMENT condition especially: it's what keeps column descriptions alive later in your diagram and spec documents.

Always name the DBMS, too. MySQL and PostgreSQL differ in types and syntax, and without a target you sometimes get a mix of both that runs on neither.

Some things are better left out. Qualifiers like "production-grade" or "perfect" barely change the result. One concrete business rule beats them all: add "reviews survive when a member deletes their account" and the AI starts reasoning about delete policies and NULLs on its own.

If your requirements aren't written down yet, that's also a job for the conversation: start with "what data would a book club service need?", shape the list together, then request DDL in the format above.

From DDL to diagram

The DDL that came back from the prompt above starts like this:

CREATE TABLE members (
  id               BIGINT AUTO_INCREMENT PRIMARY KEY,
  email            VARCHAR(255) NOT NULL UNIQUE COMMENT 'Login account',
  nickname         VARCHAR(50)  NOT NULL COMMENT 'Display name',
  current_group_id BIGINT NULL COMMENT 'Current active group',
  joined_at        DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Joined at'
) COMMENT='Members';

CREATE TABLE reading_groups (
  id         BIGINT AUTO_INCREMENT PRIMARY KEY,
  owner_id   BIGINT NOT NULL COMMENT 'Group owner',
  name       VARCHAR(100) NOT NULL COMMENT 'Group name',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created at',
  CONSTRAINT fk_groups_owner FOREIGN KEY (owner_id) REFERENCES members (id)
) COMMENT='Reading groups';

Five tables in total with books, group_books and reviews — at first glance, nothing to complain about. Paste it into WorksCove ERD's SQL schema import and the diagram appears with every relationship line connected. Structure you couldn't see in text suddenly is visible. If the symbols on the relationship lines are unfamiliar, the ERD notation guide has them. The import flow itself is covered step by step in SQL to ERD.

The step that actually matters: verifying AI output

Here's the part this article really wants to say. Review enough AI-generated schemas and a pattern emerges: AI is remarkably good at carving out entities and pointing relationships the right way, and it quietly misses the things that cause incidents in production.

Here's the book club schema above, run through automated validation:

Validation results for the AI-designed schema — circular reference detected, missing FK indexes flagged (WorksCove ERD)

Seven warnings, every one of them a real-world problem.

Circular reference. members.current_group_id points at reading_groups, while reading_groups.owner_id points back at members. With the two tables referencing each other, neither can be inserted first in a clean state, and backup restore order becomes a puzzle. "A member's current group" should be a membership history table (group_members), not a column — the AI compressed "can join groups" from the requirements into a single column.

Missing FK indexes. Columns that will carry joins, like reviews.member_id, have no index. Invisible while data is small, then queries slow down noticeably once reviews hit the hundreds of thousands — a classic time-bomb.

UNIQUE column length. email VARCHAR(255) UNIQUE is a common habit, but under MySQL utf8mb4 it exceeds the recommended index key length (191 chars). The kind of thing that separates using a convention knowingly from using it blindly.

Beyond these three, a few more types keep showing up across AI schemas:

  • It invents constraints the requirements never stated. The rating column lands as TINYINT but the 1-5 range check is missing — or the opposite, a CHECK constraint nobody asked for appears. Decisions you didn't make are sitting in your schema, so read it line by line.
  • Similar columns get different types in different tables. One table's name column is VARCHAR(50), another's is VARCHAR(100). A human team catches this with conventions; AI generates table by table, so cross-table consistency is weak.
  • Delete policies are simply absent. Without explicit ON DELETE, the DBMS default (RESTRICT) applies — and whether that matches your service's needs is a question nobody has examined. "What happens to reviews when a member leaves?" has no answer in the schema.

Catching all of this by eye is hard. WorksCove ERD's data validation checks 25 items automatically — circular references, missing indexes, reserved words, type validity and more — and rolls them up into a quality score. The more design you delegate to AI, the more this verification step is worth. AI made drafting fast; deciding whether the draft can be trusted is still the job of people and tools.

Feeding warnings back to the AI

Return the validation warnings to the AI and the loop closes. We took the circular reference warning above and asked:

This schema has a circular reference between
members.current_group_id and reading_groups. Remove the
current_group_id column and redesign it with a separate
membership history table.

The revision that came back:

CREATE TABLE group_members (
  group_id  BIGINT NOT NULL COMMENT 'Group',
  member_id BIGINT NOT NULL COMMENT 'Member',
  joined_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Joined at',
  PRIMARY KEY (group_id, member_id),
  CONSTRAINT fk_gm_group  FOREIGN KEY (group_id)  REFERENCES reading_groups (id),
  CONSTRAINT fk_gm_member FOREIGN KEY (member_id) REFERENCES members (id)
) COMMENT='Group membership';

The cycle is gone — and "can a member join several groups?", a question the original schema fudged, now has an answer. Re-importing the revised DDL and re-running validation takes minutes. The design → verify → revise loop spins much faster than it ever did between humans alone.

If you want Mermaid instead

If the goal is a diagram embedded in a README or docs, asking for Mermaid works too:

erDiagram
  MEMBERS ||--o{ REVIEWS : "writes"
  BOOKS   ||--o{ REVIEWS : "receives"
  READING_GROUPS ||--o{ GROUP_BOOKS : "picks"

It renders right inside Markdown, which is plenty for lightweight sharing. But it can't carry types, indexes or comments, and getting from here to a real database means producing DDL after all. So flip the order: get DDL first, convert to Mermaid when you need it. The other direction loses information.

Prompts for when a database already exists

AI isn't just for greenfield design — it's just as useful against a database that already exists. The key is feeding it the current schema as material.

Designing tables for a new feature. Paste your current DDL and ask "what tables would a coupon feature need? Follow the existing naming conventions." The proposal comes back matching your snake_case, your prefixes, your style — a different level of quality than asking without the schema.

Reviewing existing structure. "Where will this schema hurt once data accumulates?" gets you opinions on normalization and indexing. Treat them as opinions, though — they complement automated validation rather than replace it.

If exporting your current DDL sounds like a chore, step 1 of SQL to ERD collects the commands per DBMS. One line of mysqldump does it.

The division of labor, summarized

What to hand the AI, and what to keep for people and tools:

  • AI: drafting a schema from requirements, revising it against validation warnings, proposing tables for new features on an existing schema
  • People and tools: reading the diagram, catching defects with automated validation, judging whether business rules (delete policies, NULLs) match what the service actually needs

If you want the by-hand fundamentals, How to Draw an ERD walks through them from the start. AI can walk those steps for you now — but someone who can read and fix the output gets a different result from someone who can't.

FAQ

Can I use an AI-designed schema as is?

It makes an excellent draft, but putting it straight into production isn't advisable. AI gets relationships and normalization mostly right, while quietly missing the things that hurt in operation — circular references, missing indexes, questionable type choices. Turn it into a diagram, look at it, run automated validation, then use it.

Which AI is best at ERDs?

Any recent conversational model handles schema design at this scale without much trouble. What moves quality far more than model choice: how concretely you state the requirements, whether you pin the output format to DDL, and whether you verify what comes back.

What about getting an image or Mermaid instead?

Mermaid is fine if the goal is a diagram embedded in documentation. But images and Mermaid are hard to edit or carry into a spec afterward. DDL flows on to diagram tools, databases and documents alike, so it's the better default — you can always convert DDL to Mermaid later, while the reverse loses information.

Is AI useful when a database already exists?

Yes — for designing tables for a new feature, or reviewing the current structure. Paste the current schema DDL and ask something like "what tables would a coupon feature need, following these conventions?" and the proposal will match your existing naming and style.