# Drawing SQL tables

I'd like to draw SQL tables, some example content and relations between the id's. Output should be something like below, without the contents.

Could you help me with a head start here? Is there any libraries for this already?

-
I would suggest to use UML, as it is the correct way of relational database presentation tool. If you wanna go that way, then you can have a look at TikZ-UML. – Pouya May 26 '14 at 11:16

An example with some matrix nodes. Fixing nodes width is necessary to correctly draw empty cells borders.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}[
table/.style={matrix of nodes, nodes in empty cells, column sep=-\pgflinewidth, row sep=-\pgflinewidth, nodes={draw,anchor=center,minimum width=2cm,minimum height=2cm}, row 1/.style={nodes={minimum height=1cm}}}]

\matrix(Dept) [table, label=above:Department] {
No & Name \\ & \\};

\matrix(Professor) [table, label=above:Professor, right=1cm of Dept] {
No & Name & DeptNo & Courses \\ & & & \\};

\matrix(Course) [table, label=above:Course, below=1.25cm of Dept] {
No & DeptNo & Prof ID & Unit \\ & & & \\};

\matrix(Student) [table, label=above:Course, right=1cm of Course] {
ID & Name & Course \\ & & \\};

\draw (Dept-2-1.south)--++(0,-.5)-|(Professor-2-3);
\draw (Professor-2-4.south)--++(0,-.75)-|(Course-1-1.north);
\draw (Course-2-1.south)--++(0,-.5)-|(Student-2-3.south);
\end{tikzpicture}
\end{document}


-
Thanks. Very useful answer. However, I do have problems with migrating this into article document class. \usetikzlibrary{matrix,positioning} isn't working in article. – t-my Jun 3 '14 at 12:23
@t-my you need to include \usepackage{tikz} before usetikzlabry. The example didn't use it because standalone class automatically loads it with tikz option. – Ignasi Jun 3 '14 at 12:32