Diagram guides · Updated October 2026

ER diagram generator: getting entities, keys and relationships right

An ER diagram is a picture of what a system stores before any table exists. It answers three questions and no others: what things do we keep records of, what do we know about each one, and how do those things connect. This guide covers how to choose your entities, how to read the fork-and-bar marks on a relationship line, and how to get an entity relationship diagram out of a description instead of a blank page.

What you describe

A library lends books to members. Each loan belongs to one member and one copy, and a copy can be lent many times. Draw this as an erDiagram.

What comes back

  • Three entity boxes, named and keyed
  • Forks and bars stating the cardinality
  • The Mermaid code, next to the preview
  • A zoomable view and an SVG download
Open Flowchart Answers →Explain a diagram I photographed

One diagram per answer, so ask for one subject area at a time.

What an ER diagram is for, and what it is not for

An entity relationship diagram describes data at rest. Nothing on it moves, nothing happens in an order, and no step follows another. That is the whole distinction from a flowchart, which is about sequence, and it is the reason a model drawn as boxes-and-arrows usually fails a review even when the boxes are named correctly.

It is also not a class diagram. Both draw rectangles joined by lines, but a class diagram carries methods, visibility markers and inheritance, and an ER diagram carries none of those. If you are unsure which of the two your assignment wants, the test is simple: if the boxes do things, you want classes. If the boxes are things, you want entities. The diagram type guide walks through the rest of the choices.

Entities, attributes and relationships

An entity is a noun you keep many separate records of and need to tell apart. Write it in the singular and in capitals, because that is the convention every marker expects and it stops you quietly turning STUDENT into a list of students. An attribute is one fact about one instance of that entity, and it only belongs there if it has exactly one value per record.

A relationship is the verb between two entities, and it is worth naming properly. Here is the library model from the panel above, written out in full:

erDiagram
  MEMBER ||--o{ LOAN : takes
  COPY   ||--o{ LOAN : "is lent on"
  MEMBER {
    int    memberId PK
    string name
    date   joined
  }
  LOAN {
    int  loanId PK
    date dueOn
  }

Two details in there matter. PK marks the key that identifies a record, and a relationship label containing a space has to sit inside quotes or Mermaid will read the second word as syntax. That quoting rule is the single most common reason a draft renders as an error message instead of a diagram.

Reading crow's foot cardinality

Each end of a relationship line carries two marks, and they are read from the entity outwards. The mark touching the box is the maximum; the one just behind it is the minimum. A fork means many, a bar means one, a circle means zero. Four combinations cover nearly everything you will ever draw:

||--||Exactly one, both waysOne row here matches one row there, always. Rare, and usually a sign the two entities should have been one.
||--o{One to zero or manyThe everyday case. One customer, any number of orders, including none yet.
||--|{One to one or manySame shape, but the child side is compulsory. An invoice with no lines on it is not allowed to exist.
}o--o{Many to manyLegal to draw and almost always wrong to leave. Split it with a third entity that holds the facts about the pairing.

Say each line out loud in both directions before you accept it. One member takes zero or more loans; one loan is taken by exactly one member. If the sentence sounds wrong in either direction, the marks are wrong, and the marks are what a marker reads first.

Weak entities and identifying relationships

This is the part that separates a model that works from one that merely looks tidy. A regular entity has a key that identifies it anywhere: a member number means something on its own. A weak entity does not. An invoice line numbered three is meaningless until you say which invoice, so its key is the invoice key plus the line number.

The relationship that lends the borrowed half of that key is the identifying relationship, and it is the only one a weak entity cannot be detached from. Mermaid draws an identifying relationship with a solid line and a non-identifying one with a dotted line, which is the same convention your textbook uses:

erDiagram
  INVOICE ||--|{ LINE : contains
  LINE }o..o| PRODUCT : names

The solid line says a line cannot exist without its invoice. The dotted one says a line points at a product but is not identified by it, so the product can be retired without taking the line with it. Getting those two the right way round is usually worth more marks than redrawing the layout.

How to ask for an erDiagram rather than a flowchart

The generator on Flowchart Answers leans towards a top-down flowchart when the prompt does not say otherwise, and a description of entities reads very much like a description of steps. Naming the type fixes it. Start the prompt with the word erDiagram and the draft comes back in the right notation.

The rest of the prompt should read like a specification rather than a wish. Name every entity in capitals, state each relationship as a verb, and give the cardinality in words. For example: an erDiagram where one DEPARTMENT employs many STAFF, each STAFF member belongs to exactly one DEPARTMENT, and a STAFF member may supervise many other STAFF.

That last clause is a relationship from an entity back to itself, which is worth asking for explicitly because it is easy to leave out and hard to add later. If you want the same technique applied to processes rather than data, the flowchart guide covers prompts for steps and decisions.

Correct the code, do not re-roll the prompt

The Mermaid source appears beside the preview and you can edit it in place, with the picture redrawing as you type. That changes the whole workflow. Asking again for a slightly different diagram gives you a slightly different everything; changing one character changes one thing.

So treat the first answer as a skeleton. Fix the cardinality by swapping a symbol, rename a relationship by editing its label, add the attribute block the draft left out. The one gotcha worth memorizing is that a label containing a bracket or a quote must itself be quoted. A node written as G[Sugar (food)] breaks the parse, because the bare bracket is read as structure, and one bad label takes the entire diagram down rather than just that box. Written as G["Sugar (food)"] it renders.

When the shape is right, zoom the preview to check that nothing has collided and download it as SVG. Vector means it stays sharp wherever you place it. What the tool will not do is read your existing database: there is no connection to a server and no SQL import, so a schema you already have needs pasting in as a description.

Four mistakes that cost marks

An attribute promoted to an entityA box called PHONE NUMBER with one field in it is an attribute wearing a costume. Fold it back into the entity it describes unless a person can have several and you need to know which is current.
Cardinality left off the lineA plain line between two boxes says they are connected and nothing else. The whole value of the notation is in the ends, so every relationship should state its minimum and maximum on both sides.
A repeating group inside one entityColumns named subject1, subject2 and subject3 are a relationship that has not been drawn yet. Pull them out into their own entity with a one-to-many line back.
Relationships named with the word hasIf every line on the sheet says has, the diagram carries no meaning beyond its shape. Name the verb that actually applies: places, supervises, is enrolled in, is shipped to.

A fifth one is scale. Past roughly a dozen entities a single sheet stops explaining anything, so split the model by subject area and repeat the entities that straddle the boundary. If you are starting from nothing at all and are not sure which shapes to reach for, the beginner guide to drawing a diagram is the better first stop.

ER diagram FAQ

What is the difference between an entity and an attribute?

An entity is a thing the system stores many separate copies of, and each copy needs to be told apart from the others. An attribute is a single fact about one of those copies. Address is usually an attribute of a customer, because you only ever read it as part of that customer. It becomes an entity the moment one customer can have several addresses, or an address needs a status of its own, because then it has an identity and a life cycle that the customer record cannot carry.

How do I read crow's foot notation?

Each end of the line carries two marks. The one touching the entity is the maximum and the one just behind it is the minimum. A three-pronged fork means many, a vertical bar means one, and a small circle means zero. So the right-hand end of STUDENT ||--o{ ENROLLMENT has the fork against ENROLLMENT and a circle behind it, which reads as zero or more enrollments, while the left end reads as exactly one student.

What is a weak entity?

A weak entity has no key that identifies it on its own. A line on an invoice is the usual example: line number three means nothing until you say which invoice it belongs to, so its key is the invoice key plus the line number. The relationship that supplies the borrowed part of the key is called an identifying relationship, and Mermaid draws it with a solid line while a non-identifying relationship uses a dotted one.

Why did my request come back as a flowchart?

The generator leans towards graph TD when nothing tells it otherwise, and a description of entities reads a lot like a description of steps. Put the word erDiagram in the first line of your prompt and the problem goes away. If a draft still arrives as boxes and arrows, you can change the first line of the code yourself rather than asking again.

Can it build an ER diagram from my existing database?

No. There is no database connection and no SQL import, so nothing is read from a live schema or a dump file. What you get is a diagram of the model you describe in words. If you already have a schema, paste the table names, their key columns and how they join into the prompt, and work from the draft that comes back.

How do I show a many-to-many relationship?

Do not draw a fork at both ends and leave it there. A many-to-many relationship always hides a third entity holding the facts that belong to the pairing rather than to either side, such as the date a student joined a course or the grade they earned. Name that entity, put it between the two originals, and give it a one-to-many relationship from each.

How many entities should one ER diagram have?

Enough to answer the question being asked and no more. A diagram meant to explain a subject area to a reader stays readable up to roughly a dozen entities. Past that, split it: one diagram per subject area, with the entities that cross the boundary repeated on both. A single sheet holding every table in a system is a reference document, not an explanation.

Can I download the ER diagram?

Yes, as SVG. That is a vector file, so it stays sharp at any size and can be placed in a report or a slide without going soft at the edges. You can also zoom the preview before downloading to check that long entity names have not collided.

Is an ER diagram the same as a class diagram?

They look similar and answer different questions. An ER diagram describes data at rest: what is stored, what identifies it, and how records relate. A class diagram describes code, so it carries methods, visibility and inheritance, none of which an ER diagram has. If your boxes have behaviour in them you want a class diagram instead, which the same tool will draw.

Tools: Flowchart Answers · Video Answers · Ask Questions

Draw an ER diagramWatch it explained