Skip to documentation content

Documentation · Data

Entity relationship

Declare every entity with its attributes, then the relations between them. The crow's foot at each end says how many, and a relation runs from the key it names to the key it names.

When to use it

Describe a data model with entities, attributes, primary/foreign keys and cardinalities.

A relation can reference TABLE.field rather than the whole table. The ERD layout reads across so key-to-key relations meet the correct rows.

Working example

Copy this complete example into the Source tab, then press Generate. Change its labels or values to make your first version.

Tingraph source
erd "Airline Booking" {
  entity PASSENGER "passengers" {
    pk "id" "bigint"
    "first_name" "varchar(50)"
    "last_name" "varchar(50)"
    "passport_number" "varchar(20)" unique
    "country_of_residence" "varchar(50)" null
  }

  entity BOOKING "booking" {
    pk "booking_id" "bigint"
    fk "passenger_id" "bigint"
    fk "flight_id" "bigint"
    "status" "varchar(20)"
    "booking_platform" "varchar(20)"
  }

  entity FLIGHT "flights" {
    pk "flight_id" "bigint"
    fk "airline_id" "bigint"
    "departing_gate" "varchar(20)"
    "arriving_gate" "varchar(20)"
  }

  entity AIRLINE "airline" {
    pk "airline_id" "bigint"
    "airline_name" "varchar(50)"
    "country" "varchar(50)"
  }

  weak BAGGAGE "baggage" {
    pk "id" "bigint"
    fk "booking_id" "bigint"
    "weight_in_kg" "decimal(4,2)"
  }

  PASSENGER one -> many BOOKING "makes"
  AIRLINE one -> many FLIGHT "operates"
  FLIGHT one -> many BOOKING "carries"
  BOOKING one -.-> many BAGGAGE "checks in"
}

Syntax reference

The same reference used by the editor and AI briefing. Syntax is notation-specific; use the keywords listed here.

Diagram

SyntaxMeaning
erd "Title" {open an entity relationship diagram
entity E "table" {an entity, with its attributes inside
weak E "table" {one that needs its owner to be told apart

Attributes

SyntaxMeaning
"name" "type"one attribute row
pk "id" "bigint"primary key
fk "owner_id" "bigint"foreign key; pfk for both
"email" "varchar" uniqueunique
"closed_at" "date" nullmay be missing; drawn as type?

Relations

SyntaxMeaning
A -> Bone to many, the usual case
A one -> many Bthe crow's foot at each end
A many -> one B "label"and what the relation is called
A -.-> Bnon-identifying (dashed)
endsone, many, one-or-many, zero-or-one

Which columns it joins

SyntaxMeaning
A.id -> B.a_idleaves that key and meets that one
left outthe keys are paired up on their names
panelor set it in Tables, beside the relation

Language rules

  • The file is one erd "Title" { ... } block.
  • An entity is entity ID "table" { ... }, and every attribute inside it is written in quotes.
  • An attribute is "name" "type", optionally opened with pk, fk or pfk and closed with unique or null.
  • A relation is A one -> many B; leaving both ends out means one to many.
  • The ends are one, many, one-or-many and zero-or-one. A dashed arrow is non-identifying.
  • Either end may name the column it joins: PASSENGER.id one -> many BOOKING.passenger_id. Left out, the primary key is paired with the foreign key named after it.

Edit on the canvas

  • Select a table to edit its fields through the panel or on-sheet row controls.
  • Join relations to the specific key rows using their port dots. Edit endpoints, labels and cardinalities in the entity panel.

Generate replaces the drawing from source. Save before generating again if you want to preserve manual finishing touches.

Read Saving & exporting

Write it with an assistant

Tingraph AI already knows this notation. For another assistant, copy the tutorial below, describe your diagram under MY DIAGRAM, then paste the returned source into the editor. This prompt includes every syntax row, rule and working example above.

Read the complete prompt
You are writing Tingraph source. Tingraph is a small text language that draws a entity relationship diagram. Answer with Tingraph source only.

SYNTAX
Diagram
  erd "Title" {               open an entity relationship diagram
  entity E "table" {          an entity, with its attributes inside
  weak E "table" {            one that needs its owner to be told apart

Attributes
  "name" "type"               one attribute row
  pk "id" "bigint"            primary key
  fk "owner_id" "bigint"      foreign key; pfk for both
  "email" "varchar" unique    unique
  "closed_at" "date" null     may be missing; drawn as type?

Relations
  A -> B                      one to many, the usual case
  A one -> many B             the crow's foot at each end
  A many -> one B "label"     and what the relation is called
  A -.-> B                    non-identifying (dashed)
  ends                        one, many, one-or-many, zero-or-one

Which columns it joins
  A.id -> B.a_id              leaves that key and meets that one
  left out                    the keys are paired up on their names
  panel                       or set it in Tables, beside the relation

RULES
- The file is one `erd "Title" { ... }` block.
- An entity is `entity ID "table" { ... }`, and every attribute inside it is written in quotes.
- An attribute is `"name" "type"`, optionally opened with `pk`, `fk` or `pfk` and closed with `unique` or `null`.
- A relation is `A one -> many B`; leaving both ends out means one to many.
- The ends are `one`, `many`, `one-or-many` and `zero-or-one`. A dashed arrow is non-identifying.
- Either end may name the column it joins: `PASSENGER.id one -> many BOOKING.passenger_id`. Left out, the primary key is paired with the foreign key named after it.

WORKED EXAMPLE
erd "Airline Booking" {
  entity PASSENGER "passengers" {
    pk "id" "bigint"
    "first_name" "varchar(50)"
    "last_name" "varchar(50)"
    "passport_number" "varchar(20)" unique
    "country_of_residence" "varchar(50)" null
  }

  entity BOOKING "booking" {
    pk "booking_id" "bigint"
    fk "passenger_id" "bigint"
    fk "flight_id" "bigint"
    "status" "varchar(20)"
    "booking_platform" "varchar(20)"
  }

  entity FLIGHT "flights" {
    pk "flight_id" "bigint"
    fk "airline_id" "bigint"
    "departing_gate" "varchar(20)"
    "arriving_gate" "varchar(20)"
  }

  entity AIRLINE "airline" {
    pk "airline_id" "bigint"
    "airline_name" "varchar(50)"
    "country" "varchar(50)"
  }

  weak BAGGAGE "baggage" {
    pk "id" "bigint"
    fk "booking_id" "bigint"
    "weight_in_kg" "decimal(4,2)"
  }

  PASSENGER one -> many BOOKING "makes"
  AIRLINE one -> many FLIGHT "operates"
  FLIGHT one -> many BOOKING "carries"
  BOOKING one -.-> many BAGGAGE "checks in"
}

OUTPUT
- Reply with one fenced code block and nothing else.
- The block starts with `erd "…" {` and ends with `}`.
- Do not invent keywords: use only the ones listed above.
- Keep labels short enough to read inside a box, and keep every ID unique.

MY DIAGRAM
Describe what you want here, then send this message.
How AI requests, attachments and privacy work

Something unclear? Contact support or read the Privacy Policy.