-
Notifications
You must be signed in to change notification settings - Fork 14
Language
Philipp edited this page Aug 7, 2022
·
12 revisions
Table of Contents
ER models are specified in .erd
files with the erdiagram
keyword and a model name.
After the header follow options for changing the generator or notation before the specification of model elements.
Syntax Graph (click to open)
// header
erdiagram Name
// options, can be in any order
generate=off
notation=default
// model elements
entity A { id key }
entity B { id key }
relationship R { E1 -> E2 }
The generate
option enables the code generator.
Syntax Graph (click to open)
Option | Description |
---|---|
off |
Turns the code generator off. |
sql |
Generate SQL tables in form of CREATE TABLE statements. |
The notation
option changes the representation in the ER diagram to a specific notation.
See Notations for more information.
Syntax Graph (click to open)
Option | Description |
---|---|
default |
Default Notation |
chen |
Chen Notation |
minmax |
Min-Max Notation |
bachman |
Bachman Notation |
crowsfoot |
Crow's Foot Notation |
uml |
UML Notation |
An entity
includes a name and attributes within curly braces.
Syntax Graph (click to open)
// Basic Entity
entity Basic {}
// Entity with Attributes
entity WithAttr {
attr1 key
attr2
}
The preceding weak
keyboard defines a weak entity. While a key
attribute is used in strong entities, weak entities use a partial-key
for identification. The dependency is declared with an additional weak relationship
.
entity StrongEntity {
attr key
}
weak entity WeakEntity {
attr partial-key
}
weak relationship depends {
WeakEntity -> StrongEntity
}
⚠️ (experimental)
entity Vehicle {
manufacturer
cost
}
entity Car extends Vehicle {
serial_nr
}
Syntax Graph (click to open)
// Basic
attr
// Datatype
attr: VARCHAR(255)
attr : integer
// Classifiers
attr key
attr partial-key
attr optional
attr derived
attr multi-valued
Syntax Graph (click to open)
Classifier | Description |
---|---|
none |
Simple |
key |
Key attributes uniquely identify entities |
partial-key |
Partial key, used for weak entities |
optional |
Optional attributes can have no value (i.e., NULL) |
derived |
Can be derived from another attribute (e.g., age from birthday) |
multi-valued |
UML Notation |
Syntax Graph (click to open)
relationship Binary {
E1 -> E2
}
relationship Ternary {
E1 -> E2 -> E3
}
relationship Recursive {
E1 -> E1
}
relationship OneToOne {
E1 [1] -> E2 [1]
}
relationship OneToMany {
E1 [1] -> E2 [N]
}
relationship ManyToMany {
E1 [N] -> E2 [N]
}
relationship Custom {
E1 ["custom"] -> E2 ["(1, *)"]
}
Single-line and multi-line comments are supported.
// single-line comment
/*
multi-line comment
*/
Usage
Development