生成实体关系图,然后从中生成 SQL

生成实体关系图,然后从中生成 SQL

使用 LaTeX 或类似的文本宏工具/库,如何生成实体关系图,然后从中生成 SQL?

答案1

运行texdoc pst-dbicons后会得到 的文档pst-dbicons,但是没有可以生成相应sql代码的包。

答案2

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-er2}

\begin{document}

\begin{tikzpicture}[entity/.style={draw=blue!50, fill=blue!20, thick, rectangle, minimum width=10mm, minimum height=7mm}, attribute/.style={draw=black, fill=white, thick, ellipse, minimum width=10mm, minimum height=7mm}, relationship/.style={draw=red!50, fill=red!20, thick, diamond, minimum width=10mm, minimum height=7mm, aspect=2}]

\node[entity] (user) {User};
\node[attribute] (userid) [above left of=user] {\key{user\_id}} edge (user);
\node[attribute] (name) [above of=user] {name} edge (user);
\node[attribute] (email) [above right of=user] {email} edge (user);
\node[attribute] (password) [right of=user] {password} edge (user);

\node[entity] (product) [below of=user] {Product};
\node[attribute] (productid) [above left of=product] {\key{product\_id}} edge (product);
\node[attribute] (pname) [above of=product] {name} edge (product);
\node[attribute] (price) [above right of=product] {price} edge (product);
\node[attribute] (description) [right of=product] {description} edge (product);
\node[attribute] (categoryid) [below right of=product] {category\_id} edge (product);

\node[entity] (category) [below of=product] {Category};
\node[attribute] (categoryid2) [above left of=category] {\key{category\_id}} edge (category);
\node[attribute] (cname) [above of=category] {name} edge (category);
\node[attribute] (description2) [above right of=category] {description} edge (category);
\node[attribute] (parentid) [below left of=category] {parent\_id} edge (category);

\node[entity] (order) [right of=product, xshift=5cm] {Order};
\node[attribute] (orderid) [above left of=order] {\key{order\_id}} edge (order);
\node[attribute] (userid2) [above right of=order] {user\_id} edge (order);
\node[attribute] (productid2) [below left of=order] {product\_id} edge (order);
\node[attribute] (quantity) [below of=order] {quantity} edge (order);
\node[attribute] (date) [below right of=order] {date} edge (order);

\node[entity] (payment) [below of=order] {Payment};
\node[attribute] (paymentid) [above of=payment] {\key{payment\_id}} edge (payment);
\node[attribute] (amount) [left of=payment] {amount} edge (payment);
\node[attribute] (paymentmethod) [right of=payment] {payment\_method} edge (payment);
\node[attribute] (orderid2) [below left of=payment] {order\_

相关内容