Example: Entity-Relationship diagram

Published 2009-08-06 | Author: Pável Calado

Example of an Entity-Relationship diagram, built using Tikz and the tikz-er2 package (available at http://tagus.inesc-id.pt/~pcalado/tikzer2/tikz-er2.html)

Download as: [PDF] [TEX]  •  [Open in writeLaTeX]

Entity-Relationship diagram

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.

% Author: Pável Calado
% the tikz-er2.sty package is available at:
% http://tagus.inesc-id.pt/~pcalado/tikzer2/tikz-er2.html






\tikzstyle{every entity} = [top color=white, bottom color=blue!30, 
                            draw=blue!50!black!100, drop shadow]
\tikzstyle{every weak entity} = [drop shadow={shadow xshift=.7ex, 
                                 shadow yshift=-.7ex}]
\tikzstyle{every attribute} = [top color=white, bottom color=yellow!20, 
                               draw=yellow, node distance=1cm, drop shadow]
\tikzstyle{every relationship} = [top color=white, bottom color=red!20, 
                                  draw=red!50!black!100, drop shadow]
\tikzstyle{every isa} = [top color=white, bottom color=green!20, 
                         draw=green!50!black!100, drop shadow]

\begin{tikzpicture}[node distance=1.5cm, every edge/.style={link}]

  \node[entity] (emp) {Employee};
  \node[attribute] (ename) [above=of emp] {Name} edge (emp);
  \node[attribute] (enum) [above right=of emp] {\key{Number}} edge (emp);

  \node[isa] (isa) [below=1cm of emp] {ISA} edge (emp);

  \node[entity] (mec) [below left=1cm of isa] {Mechanic} edge (isa);
  \node[entity] (sal) [below right=1cm of isa] {Salesman} edge (isa);

  \node[relationship] (does) [left=of mec] {Does} edge (mec);

  \node[weak entity] (rep) [below=of does] {RepairJob} edge (does);
  \node[attribute] (rnum) [left=of rep] {\discriminator{Number}} edge (rep);
  \node[attribute] (desc) [above left=of rep] {Description} edge (rep);
  \node[attribute] (cost) [below left=of rep] {Cost} edge (rep);
  \node[attribute] (mat) [left=0.5cm of cost] {Parts} edge (cost);
  \node[attribute] (work) [below left=0.5cm of cost] {Work} edge (cost);

  \node[ident relationship] (reps) [below=of rep] {Repairs} edge [total] (rep);

  \node[entity] (car) [right=of reps] {Car} edge [<-] (reps);
  \node[attribute] (lic) [above=of car] {\key{License}} edge (car);
  \node[attribute] (mod) [below=of car] {Model} edge (car);
  \node[attribute] (year) [below right=of car] {Year} edge (car);
  \node[attribute] (manu) [below left=1.5cm of car] {Manufacturer} edge (car);
  \node[relationship] (buy) [below=of sal] {Buys};
  \node[attribute] (pri) [above left=of buy] {Price} edge (buy);
  \node[attribute] (sdate) [left=of buy] {Date} edge (buy);
  \node[attribute] (bval) [below left=of buy] {Value} edge (buy);

  \node[relationship] (sel) [right=of buy] {Sells};
  \node[attribute] (sdate) [above right=of sel] {Date} edge (sel);
  \node[derived attribute] (sval) [right=of sel] {Value} edge (sel);
  \node[attribute] (com) [below right=of sel] {Comission} edge (sel);
  \draw[link] (car.10) -| (buy) (buy) edge (sal);
  \draw[link] (car.-10) -| (sel) (sel) |- (sal);

  \node[entity] (cli) [below right=0.5cm and 3.7cm of car] {Client};
  \node[attribute] (cid) [right=of cli] {\key{ID}} edge (cli);
  \node[attribute] (cname) [below left=of cli] {Name} edge (cli);
  \node[multi attribute] (cphone) [below right=of cli] {Phone} edge (cli);
  \node[attribute] (cadd) [below=of cli] {Address} edge (cli);

  \draw[link] (cli.70) |- node [pos=0.05, auto, swap] {buyer} (sel);
  \draw[link] (cli.110) |- node [pos=0.05, auto] {seller} (buy);




  • #1 cakoy, August 24, 2009 at 4:57 a.m.

    wow very good!

  • #2 renante rillo, February 5, 2010 at 4:49 p.m.

    sir what programming language you used in that diagram? That diagram really help me in doing our case study...Sir can you do a flowchart in ENROLLMENT SYSTEM and PAYROLL SYSTEM. Just a guide in our case study.

    thank you very much...

  • #3 david vivien, March 3, 2010 at 11:59 a.m.

    how could we implement this ER diagram on microsoft access?

  • #4 sai, February 16, 2012 at 6 p.m.

    hello sir i need an ER diagram for a car and its manufacturer relationship... lz guide me for er diagram..

  • #5 sandra, March 2, 2012 at 3:53 p.m.

    The link is not up to date. The new link is:


  • #6 Nick, March 5, 2012 at 6:12 p.m.

    Nice example, thanks!

    The other comments are entertaining..

  • #7 mukhtiyar hussain, June 7, 2012 at 3:28 p.m.

    sir can you explain E-R diagrame for medical store management,and a link where i can download it..

  • #8 daryl nogoy, July 1, 2012 at 11:46 a.m.

    @Mr.Vianzon.. haha aus ahh umabot k pti dito

  • #9 rimla, November 20, 2012 at 10:24 a.m.

    how can we convert this diagrame in relations or in table.plz tell me in detail

  • #10 Figaw, November 27, 2012 at 4:47 p.m.

    I found this very pretty and useful!

    I would really like to contribute to this project, but I am having difficulties finding out how to contact you author :/

  • #11 lol, March 24, 2013 at 5:37 p.m.

    God... people read a book on DB, please. Stop asking questions not related to LaTex and Tikz... do your homework!

  • #12 MAnuel, October 31, 2013 at 10:54 a.m.

    Unfortunately, writeLaTeX was not able to compile the code...

Adding comments is currently not enabled.


Preorder discount 35%
coupon code LXCB35

LaTeX Beginners Guide

Limited discount 50%
coupon code tDRet6Y

click here to read whole story

Creative Commons License