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.
-
Direction. A foreign key always points from the table that holds the
column to the table it refers to, such as from
OrdertoCustomer. To flip it, click Reverse direction in the side panel, or press R. -
Key columns. Select a foreign key to see its columns in the Edit tab:
each pair is a column of the table that holds it, such as
customer_id, and the column it references, such asid. Add more pairs for a composite key. When the table lacks a matching column, Create adds one with the referenced column's data type. A new foreign key isn't tied to columns yet: Set up columns picks the referenced table's primary key and adds the matching column, and the SQL export does the same for any foreign key you leave untied. Reverse direction keeps every pair right. See Export. - On delete and on update. Choose CASCADE, RESTRICT, SET NULL, SET DEFAULT, or NO ACTION under Referential actions, or leave the database's default.
- Many-to-many. Right-click a foreign key, or select two tables, and choose Add junction table. Maowl places a new table between the two, with a foreign key to each and both columns as its primary key.
- Reconnecting. Select a foreign key and drag the handle at either end onto another table. The foreign key keeps its name, columns, and direction. To make it point to its own table, drop the handle on the table at its other end.
- Several foreign keys between two tables. They're drawn side by side, with just enough room between them for their columns.
- A foreign key to the same table. A table that refers to itself, such as an employee's manager, is drawn as a narrow loop that points toward the most open space around the table. As you move tables, it swings into place, clear of nearby tables, notes, and lines. If a table has several, they spread out across the open space.
- Layer. A new foreign key isn't in any layer (its Layer dropdown shows Default), so it's visible whenever both of its tables are. To put it in a layer, pick one from that dropdown in the Edit tab. See Layers.
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.