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, Query › Show ER Diagram, 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 (Command Palette › Database: Reload Diagram).

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 (Command Palette › Database: Tables to Show in Diagram…). In that dialog, Show Tables shows what you ticked (Command Palette › Database: Show Chosen Tables) and Cancel leaves the diagram as it is (Command Palette › Database: Cancel Table Choice).

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:

MarkerMeaning
PKPart of the primary key
FKA foreign key
UKUnique

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

ToDo this
Hide or show the outlineOutline 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 narrowerDrag its edge. Double-click the edge for its usual width.
Give the diagram the whole windowFocus (⇧⌘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, Command Palette › View: Toggle Full Screen (⌃⌘F on macOS or F11 on Windows and Linux) works in every tab.

Move around

ToDo this
PanDrag the background, or scroll with two fingers or the wheel.
ZoomPinch, 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 everythingFit (F)
Go to actual size100% (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 columnsColumns (Command Palette › Database: Toggle Diagram 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 tablePress
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.

ToDo this
Add a tableAdd 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 tableF2, or edit the name in the panel.
Add or remove a columnAdd Column (Command Palette › Database: Add Column to Diagram Table), Remove Column (Command Palette › Database: Remove Diagram Column). Edit its name, type and Allows NULL in the panel.
Add a relationshipDrag from a column to the table it should refer to, or choose Add Relationship… (Command Palette › Database: Add Relationship…), pick the table, the key and what happens on delete and update, and choose Create Relationship (Command Palette › Database: Create Relationship). Cancel gives it up (Command Palette › Database: Cancel Relationship).
Remove a table or relationshipSelect 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 commentsEdit 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:

ButtonWhat it does
ApplyRuns the statements (⌘↩ on macOS or Ctrl+Enter on Windows and Linux).
Open in EditorPuts them in a new query tab on the diagram's database, not run (Command Palette › Database: Open Diagram Changes in Editor).
CloseGoes back to the diagram (Command Palette › Database: Close Diagram Review).

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 (Command Palette › Database: Discard Diagram Changes) drops every edit not applied. Closing the tab with edits not applied asks whether to apply or discard them.

Export the diagram

To getChoose
An imageExport PNG… (Command Palette › Database: Export Diagram as PNG…)
A drawing that scalesExport SVG… (Command Palette › Database: Export Diagram as SVG…)
Text for Mermaid, which many wikis and documentation tools drawExport Mermaid… (Command Palette › Database: Export Diagram as Mermaid…), or Copy Mermaid to copy it (Command Palette › Database: Copy Diagram as Mermaid)

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