Using a LaTeX or similar text-macro tool/library, how can I generate an Entity-Relationship Diagram then generate SQL from it?
Asked
Active
Viewed 872 times
2
-
1Can you post a bit more detail as to exactly what you want. Perhaps a diagram and some code of what you have attempted. – Peter Grill Sep 15 '11 at 02:02
-
1IMHO, TikZ is the way to go for diagrams: See typesetting uml class diagrams for more options. – Peter Grill Sep 15 '11 at 02:28
-
This seems like the wrong way round. Wouldn't it be easier to write the SQL and then read that to create the diagram? Or have I misunderstood something? – Seamus Sep 20 '11 at 14:07
-
See my previous answer. I don't think it's a wrong method though, a lot of what we write is very repetitive, models which generate SQL are much more useful at this stage. – A T Sep 20 '11 at 14:33
-
I've decided to write the SQL by hand, and generate a diagram from that using SchemaSpy. Using Doc2TeX I can then embed it neatly into my TeX report. – A T Sep 19 '11 at 11:34
-
But I want people to mark it down if they think it's a bad idea, or mark it up if they think it's a good one – A T Sep 19 '11 at 15:06
2 Answers
1
Run texdoc pst-dbicons then you'll get the documentation of pst-dbicons. But there is no package which can generate the corresponding sql code.
0
\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\_
JamesT
- 3,169