绘制ER图(数据库关系图)

http://www.texample.net/tikz/examples/entity-relationship-diagram/

https://www.assembla.com/wiki/show/tikz-er2

 

\usepackage{tikz-er2}
\usetikzlibrary{positioning}
\usetikzlibrary{shadows}
\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]

\centering
\scalebox{.87}{
\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);

\end{tikzpicture}
}

 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值