Database diagrams¶
The Database section of the Library panel has what an entity-relationship diagram needs: an Entity Table, and five relationship lines under Relationships. The Entity Table is in Complex Shapes too, and UML's Database Entity places the same thing, so use whichever you find first.
Entity tables¶
An entity table is a table with a header for the table's name and a row for each field:
its name on the left, its type in small grey letters on the right. A new one starts with
Entity Name, an id and a name. Type over them.
It types like any table: double-click a cell, Tab to the next, and Tab in the last cell adds a field. It always has two columns and a header row, so its right-click menu leaves out the column commands and Header Row. In Format › Complex Shape they explain why they don't apply rather than doing something odd. It holds up to 60 fields.
Field marks¶
Click a field to choose it, then right-click: the marks are at the top of the menu. Or use Format › Complex Shape › Field Marks. Each one is a tick, on or off:
| Mark | Drawn as |
|---|---|
| Primary Key | A filled gold key |
| Foreign Key | An outlined red key |
| Unique | A filled diamond |
| Indexed | An outlined diamond |
| Nullable | A small open circle |
The marks stack in a narrow column before the names, so names stay lined up however many marks a field has. Nothing checks your database rules. A nullable primary key is between you and your DBA.
Moving fields¶
With a field chosen, Move Row Up and Move Row Down in Format › Complex Shape, or the right-click menu, move it one row at a time. They work in every table, not just entity tables, though nothing moves above a header.
The table shortcuts work here too: Alt+Up and Alt+Down insert a field above or below, and Alt+Cmd+Del deletes one.
Connecting fields¶
Every field has a connection point at each end of its row, so a relationship can run
from one field to another, such as orders.customer_id to customers.id. Add, delete
or move rows and each connector stays with its field. Delete a field and its connectors
come free where they are. The usual points round the outside are still there for a line
to the whole table.
An entity table places its own points, so it turns down Edit Connection Points.
Relationships¶
| Relationship | Start | End |
|---|---|---|
| One to One | One and Only One | One and Only One |
| One to Many | One and Only One | One or Many |
| One to Zero or Many | One and Only One | Zero or Many |
| One to Zero or One | One and Only One | Zero or One |
| Many to Many | Zero or Many | Zero or Many |
Each is a solid line with right angles and crow's-foot endings. Draw from the "one" side. As with UML relationships:
- Click a tile, then draw, and the next connector has that look.
- Drag a tile onto the page for a short connector, then drag its ends onto fields.
- Restyle lines you've drawn: select them and choose Format › Entity Relationship, or right-click one.
UML's One to Many draws the same line as One to Zero or Many.
Finding it again¶
Search all libraries and the Entity Table is listed once, from Complex Shapes, though it also sits in Database and UML. In the Shape Data panel it's called an Entity Table.