Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

Relational model

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

share|improve this question
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 at 11:16

1 Answer 1

up vote 4 down vote accepted

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

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);

enter image description here

share|improve this answer
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 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 at 12:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.