:PROPERTIES:
:ID: fd4de606-e719-4ffd-a04f-38dc5dde50c4
:mtime: 20231017030616
:ctime: 20231017030541
:END:
#+title: entity-relationship diagram
#+filetags: :public:project:
* ER Diagram
entity-relationship (ER) diagram is a technqiue to formally describe
the data we want to store in a database.
An ER diagram is a very abstract representation of data; an ER diagram
is independent of the implementation of the database
** Syntax of ER diagram
An ER diagram consists of
| how to draw | name | description |
|------------------------+--------------------------+---------------------------------------------------------|
| rectangle | entity | an entity is something in the real world |
| doubly-boxed rectangle | weak entity | weak entities depend on the existance of another entity |
| oval | attributes | an attribute is a property of an entity |
| diamond | relationship | relationships between entities |
| underlined text | key | a key uniquely identifies an instance of an entity |
| single-headed Arrow | many-to-one relationship | |
| double headed arrow | one-to-one relationship | |
* Example: Movie Database
#+BEGIN_SRC dot :file ER.png :cmdline -Kdot -Tpng :exports both
graph ER {
layout=neato
node [shape=box , style=filled, color=lightblue]; movie ; person;
node [shape=ellipse , style=filled , color = yellow]; year ; title ; birthyear ; name
node [shape=diamond,style=filled,color=red]; directed;
person -- birthyear;
person -- name;
movie -- year;
movie -- title;
person -- directed;
directed -- movie;
}
#+END_SRC
#+RESULTS:
[[file:ER.png]]