Skip to content

Language

Philipp edited this page Aug 7, 2022 · 12 revisions
Table of Contents
  1. ER
    1. Generator
    2. Notation
  2. Entity
    1. Weak Entity
    2. Inheritance
  3. Attributes
    1. Datatype
    2. Classifier
  4. Relationship
    1. Degree
    2. Cardinality
  5. Comments

ER Model

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 }  

Generator

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.

Notation

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

Entity

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
}

Weak Entity

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
}

Inheritance

⚠️ (experimental)

entity Vehicle {
    manufacturer
    cost
}

entity Car extends Vehicle {
    serial_nr
}

Attributes

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

Datatype

Syntax Graph (click to open)

Classifier

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

Relationship

Syntax Graph (click to open)

Degree

relationship Binary {
    E1 -> E2
}

relationship Ternary {
    E1 -> E2 -> E3 
}

relationship Recursive {
    E1 -> E1
}

Cardinality

relationship OneToOne {
    E1 [1] -> E2 [1]
}

relationship OneToMany {
    E1 [1] -> E2 [N]
}

relationship ManyToMany {
    E1 [N] -> E2 [N]
}

relationship Custom {
    E1 ["custom"] -> E2 ["(1, *)"]
}

Comments

Single-line and multi-line comments are supported.

// single-line comment

/*
    multi-line comment
*/
Clone this wiki locally