Maowl Open Maowl

Tables and foreign keys

Every table in your database becomes a card on the canvas, and every foreign key becomes a line from the table that holds it to the table it points to. Here's how to add them, name them, and edit them in place.

Adding tables

A new model starts with one empty table in the middle of the canvas. To add more, click Add table at the top of the side panel, or right-click an empty spot on the canvas and choose Add table to place one there. Each new table opens with boxes for its name and columns, so you can start typing right away.

Already have your tables somewhere else? Open a schema file, paste your CREATE TABLE statements, or paste a list of names to create many tables at once (see Import and merge).

Table names

The table name runs across the top of the card. Every table needs a name of its own. If you give a table a name another table already has, Maowl tells you so and highlights both tables in red until you rename one of them. The same goes for a duplicated or pasted table, which keeps the original's name. Names that differ only in case, such as OrderItem and Orderitem, count as the same name.

As you type, a table name gets a capital first letter and a foreign key name is written in capitals. Runs of capitals, such as ID or SKU, stay as you typed them, and so do spaces, underscores, and hyphens, so order_item stays order_item. When you open or import a model, its names stay exactly as written.

Captions

The band below a table's name holds its caption: the example value of its first column. To show a different caption, drag the column you want to the top of the list. If the first column has no example value, the band stays empty. In Simple mode, double-click a table to edit its caption.

Foreign keys

To add a foreign key, drag from the edge of the table that holds it to the table it points to. Fill in the name in the box that opens above the line, and press Enter. To create a new table at the same time, drop the line on an empty spot instead.

Editing on the canvas

To edit a table or foreign key, double-click it (or tap it on a tablet), or select it and press Enter, and type right inside it. Press Tab to move to the next field, and click the canvas when you're done. The same fields are in the side panel's Edit tab.

Cards or circles

By default, every table is a card: its name runs across the top in bold, the caption sits in a band of the table's fill color, and the columns fill the card in three columns: column name, data type, and example value. Turn off Square mode in the top bar to draw each table as a circle instead, with its name above it and its columns listed below. The choice applies to the whole model. To show only table names and captions, hide the Columns layer.

On cards, a foreign key runs from the row of the column that holds it to the row of the column it references, and its ends use crow's foot notation: a three-pronged foot for many, a bar for one, a second bar where a value is required, and a small circle where it's optional. A foreign key on a primary key or unique column is one-to-one. To draw plain arrowheads instead, open the Format tab with nothing selected and change Line ends under Foreign keys. Circles always use arrowheads.

Selecting and moving

Click to select. Shift-click or ⌘-click to add an item to the selection, or to remove it. To select everything in an area, ⌘-drag across it, starting from an empty spot on the canvas. (On Windows and Linux, use Ctrl instead of ⌘.) Drag any selected item to move the whole selection, or nudge it with the arrow keys: 1 px at a time, or 10 px with Shift. If you drop a table on top of another, the table you dropped slides aside to make room. When the two are connected, it leaves just enough space for the foreign key's name and columns.

To add a table that's similar to one you already have, select it and use Duplicate (⌘D). The copy has the same name, columns, and foreign keys as the original, including foreign keys to tables you didn't duplicate.

Related