Relate columns
Draw a relationship between two columns by dragging from one to the other, or add a related table in one drag.
You relate two columns by dragging from one to the other. The app adds the relationship and draws its line.
Drag from a column
- Point at a column's row, or select the column. A small ring appears at each end of the row.
- Drag one of those handles, or the row itself, towards a column in another table. A line follows the pointer and snaps to the row it would relate to.
- Read the caption. It says what dropping will do, such as "Relate to customers.id".
- Let go to add the relationship.
A new relationship is many to one. Change that with Cardinality in its bar, or in Properties.
If the two columns are already related, the caption says so and nothing is added.
Which side holds the reference
If one of the two columns is a key or unique, it's the one being pointed at. Otherwise the column you dragged from holds the reference.
To swap the sides later, choose Flip direction in the relationship's bar.
Drop on a table's header
Drop on a table's header to relate to that table's key.
Dragging from a key works differently. Drag customers.id onto the orders header and the app adds a customer_id column to orders that points at the key, as drawSQL does. If orders already has a customer_id that points at nothing, the app relates that column instead.
Drop on empty canvas
Drop on empty canvas to add a new table there, related to the column. The table opens for naming.
- From a key such as
customers.id, the new table gets acustomer_idcolumn that points at it. - From any other column, that column points at the new table's
id.
Relate a table to itself
To relate two columns of the same table, such as a comment's parent_id to its id, hold ⌥ (Alt on Windows and Linux) while you drag. Without it, dragging a row within its own table moves the column.
On a touch screen, dragging a row pans the view. Drag from the row's handle instead.