When to use it
Database course assignments and the database design chapter of a course-registration or academic-management capstone project. Students and courses are many-to-many, resolved through the enrolment entity into two one-to-many relationships, the classic ER exam question.
Making it yours
- Fields live inside the braces as
type name PK/FK; the key markers are optional. - Add an entity with a new
NAME { … }block and connect it with a relationship line. - Cardinality symbols:
||exactly one,o{zero or more,|{one or more,o|zero or one; each end describes its own side. - The word on the relationship line is a verb describing what the left entity does to the right one.
Mermaid code
erDiagram
STUDENT ||--o{ ENROLMENT : enrols
COURSE ||--o{ ENROLMENT : "is taken in"
INSTRUCTOR ||--o{ COURSE : teaches
DEPARTMENT ||--o{ STUDENT : administers
DEPARTMENT ||--o{ INSTRUCTOR : employs
STUDENT {
string student_id PK
string name
string major
int year
}
COURSE {
string course_id PK
string title
int credits
string instructor_id FK
}
ENROLMENT {
string student_id FK
string course_id FK
float grade
string term
}
INSTRUCTOR {
string instructor_id PK
string name
string rank
}
DEPARTMENT {
string department_id PK
string name
}Ask an AI for one with this structure
Send the prompt below to ChatGPT or Claude, then paste the whole reply into the editor; the code inside is detected automatically.
Draw a course enrolment system ER diagram in Mermaid erDiagram syntax with entities STUDENT, COURSE, ENROLMENT, INSTRUCTOR and DEPARTMENT. Students and courses are many-to-many through ENROLMENT (STUDENT ||--o{ ENROLMENT, COURSE ||--o{ ENROLMENT); an instructor teaches many courses; a department administers many students and employs many instructors. List the main fields of each entity with PK and FK markers. Output only the mermaid code block.FAQ
- How do I read the relationship symbols?
||--o{reads "one to zero or more": one on the left, zero to many on the right.}o--||is the reverse. Two solid dashes mean a mandatory relationship;..means optional.- Do I have to use real database types?
You can use concrete types such as
varcharanddatetimeor generic ones such asstringandint; Mermaid does not validate type names.- My course requires Chen notation with diamond relationships
Mermaid ER diagrams use crow's-foot notation: boxes for entities and lines for relationships. If Chen notation is required, draw it with a flowchart: entities
[ ], attributes(( )), relationships{ }.
More in this category
Updated 2026-09-05