ER diagrams from an AI reply: database coursework and design docs

The prompt that gets erDiagram code from an AI assistant, how entities and fields are written, cardinality symbols for one-to-many and many-to-many, generating a diagram from CREATE TABLE statements, display names and exporting for a report.

About 4 minUpdated 2026-11-11

The prompt

Draw an ER diagram for a library system with Mermaid erDiagram syntax. The entities are reader, book, loan and category. List the main fields of each entity as "type name", mark primary keys with PK and foreign keys with FK. Show relationships with cardinality symbols such as ||--o{. Give the complete mermaid code block.

If you already have the schema, paste the CREATE TABLE statements and ask the assistant to convert them to Mermaid erDiagram.

A typical result

erDiagram
    READER ||--o{ LOAN : makes
    BOOK ||--o{ LOAN : "is lent in"
    CATEGORY ||--o{ BOOK : contains
    READER {
        int id PK
        string name
        string phone
    }
    BOOK {
        int id PK
        int category_id FK
        string title
        string author
    }
    LOAN {
        int id PK
        int reader_id FK
        int book_id FK
        date borrowed_at
        date returned_at
    }
    CATEGORY {
        int id PK
        string name
    }

Edit the text, switch themes and download PNG, Word or PowerPoint from there.

Reading the cardinality symbols

Each end of a relationship line has a symbol; read it as "one on the left has how many on the right":

  • || exactly one, o| zero or one
  • |{ one or more, o{ zero or more

READER ||--o{ LOAN reads: a reader has zero or more loans, and a loan belongs to exactly one reader. Many-to-many (readers and books) needs a junction table in the database, which is LOAN above.

Display names

Letters, digits and underscores are the safest for entity and field names. For a friendlier label write the entity as READER["Library member"], and add a comment in double quotes after a field.

Putting it in a report

Use the SVG or a 3× PNG in a report so it stays sharp, and Export to PowerPoint for a presentation. With many tables, split the diagram by module into two or three; that reads better than one crowded diagram. The ER diagram templates cover course enrollment, an online shop and a library.

More guides

All guides