Entity Diagrams

An entity diagram is the tables of a database and how their rows relate. It starts with entity and its title.

entity A small shop
Customer
  id: number [key]
  name: text
  email: text [unique]
Order
  id: number [key]
  customer: number [ref]
  placed: date
Product
  id: number [key]
  title: text
  price: number
Line
  order: number [key, ref]
  product: number [key, ref]
  quantity: number
Customer 1-* Order: places
Order 1-1..* Line: holds
Product 1-* Line: appears in

The text above: Customer, Order, Product and Line with their attributes and keys, joined by crow's feet

Settings

Setting Also Value
direction flow, orientation, layout, rankdir down (the default), right, up or left

Entities and attributes

An entity is named on a line of its own, with its attributes indented under it. An attribute is a name, a colon and a type, then its keys in brackets:

Key Also Shown as
key pk, primary, primary key, id PK, and the name underlined
ref fk, foreign, foreign key, reference FK
unique uk UK

id number - a name and a type without a colon - is read as well. A name, a colon and a type written outside an entity is said: it belongs indented under one.

Relationships

A relationship is a line with a count at each end, drawn as crow's feet: Customer 1-* Order: places. Each end is one of four:

Count Also Means
1 exactly one
0..1 zero or one
1..* 1..n one or more
* 0..*, 0..n, n, many any number

The ends are joined by one, two or three dashes, and a label goes after a colon. Mermaid's crow's feet drawn in characters are read too: ||--o{ is one to any number, |o--|{ zero or one to one or more, and two dots in place of the dashes - }|..|| - draw the line dashed, for a relationship that is not identifying. A count no end can have, such as 2-*, is said.

The plain arrows draw plain lines between entities.

Groups and notes

group Name frames the entities indented under it. note Entity: what to say puts a note beside an entity.