Help › Change a database's structure
Draw an ER diagram
Draw a schema's tables and the foreign keys between them, arrange and export the picture, and add tables, columns and relationships in it.
Querlyn 0.1.0 is not released yet. This help describes it ahead of release.
An ER diagram draws the tables of a schema as boxes and the foreign keys between them as lines. Use it to find your way in a database you do not know, and to add tables and relationships where you can see them.
Open a diagram
Select a table, schema, database or connection in the sidebar, then choose ER Diagram at the top of the sidebar, , or Show ER Diagram in the right-click menu.
- From a table, the diagram opens on that table and every table it refers to or that refers to it.
- From a schema, database or connection, it shows the schema.
There is one diagram tab for each schema. The tables are read fresh from the database when the tab opens; Reload reads them again ().
A schema with up to 150 tables is shown whole. A larger one shows its first 150 tables by name; choose Tables… to pick others, up to 500 at a time (). In that dialog, Show Tables shows what you ticked () and Cancel leaves the diagram as it is ().
Read the diagram
Each table lists its columns with their types. A ? after a type means the column allows NULL. The markers in front of a column mean:
| Marker | Meaning |
|---|---|
| PK | Part of the primary key |
| FK | A foreign key |
| UK | Unique |
A line runs from a foreign-key column to the column it refers to. Its ends show how many rows can be on each side: the forked end is the "many" side. Point at a table to highlight its relationships.
Beside the picture, the outline lists every table with its columns and relationships as text, and a panel shows the selected table.
Make room for the diagram
| To | Do this |
|---|---|
| Hide or show the outline | Outline in the toolbar, ⌘7 on macOS or Ctrl+7 on Windows and Linux, or the chevron on the outline's edge. A hidden outline leaves a thin strip on the left; click it to bring the outline back. |
| Make the outline wider or narrower | Drag its edge. Double-click the edge for its usual width. |
| Give the diagram the whole window | Focus (⇧⌘F on macOS or Ctrl+Shift+F on Windows and Linux) hides the sidebar and the outline. |
| Hide or show the sidebar alone | ⌘B on macOS or Ctrl+B on Windows and Linux, or the chevron on the sidebar's edge |
Whether the outline is shown, and its width, are remembered for every diagram on this computer.
Focus Diagram ends when you choose Focus again, press ⇧⌘F on macOS or Ctrl+Shift+F on Windows and Linux again, press ⎋ on macOS or Esc on Windows and Linux with nothing selected in the diagram, or go to another tab. The sidebar and the outline then come back as they were. Showing either of them during Focus Diagram ends it too.
To use the whole screen, (⌃⌘F on macOS or F11 on Windows and Linux) works in every tab.
Move around
| To | Do this |
|---|---|
| Pan | Drag the background, or scroll with two fingers or the wheel. |
| Zoom | Pinch, or hold ⌘ on macOS or Ctrl on Windows and Linux and turn the wheel; Zoom In (⌘= on macOS or Ctrl+= on Windows and Linux) and Zoom Out (⌘- on macOS or Ctrl+- on Windows and Linux). |
| See everything | Fit (F) |
| Go to actual size | 100% (0) |
| Select the next or previous table | ⇟ on macOS or PageDown on Windows and Linux, ⇞ on macOS or PageUp on Windows and Linux |
| Show names only, without columns | Columns () |
Zoom goes from 10 % to 300 %.
Arrange the tables
Querlyn lays the tables out so that a table sits to the right of the tables it refers to. To change the layout:
- Drag a table by its title. With a table selected, the keys in the table below move it.
- Re-layout (⇧⌘L on macOS or Ctrl+Shift+L on Windows and Linux) lays everything out again and forgets where you put the tables.
| To move the selected table | Press |
|---|---|
| A little | ← on macOS or Left on Windows and Linux, → on macOS or Right on Windows and Linux, ↑ on macOS or Up on Windows and Linux, ↓ on macOS or Down on Windows and Linux |
| Further | ⇧← on macOS or Shift+Left on Windows and Linux, ⇧→ on macOS or Shift+Right on Windows and Linux, ⇧↑ on macOS or Shift+Up on Windows and Linux, ⇧↓ on macOS or Shift+Down on Windows and Linux |
Where you put a table is remembered on this computer for that connection and schema.
Change the structure in the diagram
A diagram can also change the database. As in the table designer, nothing is changed until you review and apply.
| To | Do this |
|---|---|
| Add a table | Add Table, or ⌘N on macOS or Ctrl+N on Windows and Linux. It starts with an id key column; type its name. |
| Rename the selected table | F2, or edit the name in the panel. |
| Add or remove a column | Add Column (), Remove Column (). Edit its name, type and Allows NULL in the panel. |
| Add a relationship | Drag from a column to the table it should refer to, or choose Add Relationship… (), pick the table, the key and what happens on delete and update, and choose Create Relationship (). Cancel gives it up (). |
| Remove a table or relationship | Select it and choose Delete, or press ⌘⌫ on macOS or Delete on Windows and Linux. A table is marked for dropping; Delete again takes the mark back. |
| Change defaults, indexes, checks and comments | Edit Structure… (↩ on macOS or Enter on Windows and Linux) opens the table in the table designer. Apply or discard the diagram's own changes to that table first. |
| Undo and redo an edit | ⌘Z on macOS or Ctrl+Z on Windows and Linux, ⇧⌘Z on macOS or Ctrl+Y on Windows and Linux |
Changes not yet applied are drawn in their own colors: new tables with a highlighted border, changed ones marked with a dot, dropped ones dashed and struck through.
A relationship drawn in the diagram can refer to a primary or unique key of one column. For a key of several columns, use the table designer.
Warning: Deleting a table in the diagram and applying drops the table and its rows from the database.
Review and apply
Choose Review Changes (⌘S on macOS or Ctrl+S on Windows and Linux). It shows the statements exactly as the table designer's preview does, with the same warnings. Then:
| Button | What it does |
|---|---|
| Apply | Runs the statements (⌘↩ on macOS or Ctrl+Enter on Windows and Linux). |
| Open in Editor | Puts them in a new query tab on the diagram's database, not run (). |
| Close | Goes back to the diagram (). |
Applying works as in the table designer: Querlyn checks that the tables did not change meanwhile, asks on Production, and runs the statements in one transaction where the database can. See Apply the changes.
Discard Changes () drops every edit not applied. Closing the tab with edits not applied asks whether to apply or discard them.
Export the diagram
| To get | Choose |
|---|---|
| An image | Export PNG… () |
| A drawing that scales | Export SVG… () |
| Text for Mermaid, which many wikis and documentation tools draw | Export Mermaid… (), or Copy Mermaid to copy it () |
Exports use light colors, also when Querlyn is dark, and include edits you have not applied, as drawn.
What depends on the database
- ClickHouse has no foreign keys: its tables are drawn without relationships, and Add Relationship… is not available.
- Amazon Redshift and Snowflake record foreign keys without enforcing them. The diagram draws them all the same.
Help for Querlyn 0.1.0. All help topics