Diagrams

A diagram shows tables as boxes, and the foreign keys between them as lines. When a diagram shows many tables, it can be difficult to find the tables that you need. In DbSchema, you can create several diagrams in the same design. Each diagram can show the tables of one part of your application. A table can show on several diagrams.

The Main Diagram of the shop design in DbSchema, with payments, orders, order_items and shipments in a group named Orders, a callout and a round shape named Catalog

The design, also called the model, is your DbSchema project: the tables, columns and diagrams that you see in DbSchema. The database is the real database on the server. The tasks on this page change only the design. Moving a table, grouping tables or adding a callout never changes the database. DbSchema saves the diagrams with the design in its .dbs file. Saving the design to a file needs DbSchema Pro.

Create a diagram

A diagram for each part of the application, such as orders or the product catalog, shows only the tables that you work on together.

  1. Choose Diagram → New Diagram, or press Ctrl+L.
  2. Type a Name.
  3. Pick a table in the list on the left and press Include >>.
  4. Press Ok.
The New Diagram dialog of DbSchema with the name Orders and the table shop.orders in the Current Diagram list

The new diagram opens in its own tab. Use the Select ... menu below the list on the left to select tables. Then press Include >> to add them to the diagram:

Select ... itemTables it selects
AllEvery table of the schema
Tables Not in Any DiagramThe tables that no diagram shows yet
Parent Tables of Selected Included Tables (referred)The tables that the selected tables on the right refer to
Child Tables of Selected Included Tables (referring)The tables that refer to the selected tables on the right

The other items of the Diagram menu:

Menu itemWhat it does
New Empty Diagram (Ctrl+Shift+L)Opens a diagram with no tables
Duplicate DiagramCopies the open diagram
Diagram PropertiesOpens the same dialog for the open diagram, to rename it or give it a Custom Background
Restore...Lists every diagram of the design and opens the one you pick

When you close a diagram's tab, DbSchema may ask "Save this Diagram to the Project ?". Choose Save and Close to keep the diagram in the design. Choose Don't save to delete the diagram.

Every column that is part of a foreign key has an arrow icon on its right. The icon lists the tables linked through that column. Use this icon to add the related tables to the diagram, one step at a time.

  1. Drag a table, such as orders, from the tree on the left onto the diagram.
  2. Click the arrow icon at the right of a column, such as order_id.
  3. Choose Add All, or one table, such as Add payments via payments_order_id_fkey.

The tables appear next to the table that you started from. If a table is already on the diagram, the list offers Show instead, such as Show payments via payments_order_id_fkey. If you hold Ctrl while you click the icon, the list offers more choices.

To remove a table from a diagram, right-click its header and choose Exclude from Diagram, or press Delete. The table stays in the design and in the database. Drop, in the same menu, deletes the table, as Drop a table shows.

Group tables

A group is a colored box around tables that belong together, with its name in the corner.

  1. Click the first table header, then Ctrl+click the other tables.
  2. Choose Diagram → Create Group of Tables, or Table → Create Group of Tables in the toolbar.
  3. Type the Group Name and press OK.

The group dialog also sets the group's Color. The dialog has two lists: Tables In No Group and Current Group Tables. Use Include to add tables to the group, and Exclude to remove them.

To add one more table to a group later, right-click the table and choose Grouping → Add to Group, then pick the group in the list.

Add a callout or a shape

A callout is a note on the diagram. A shape is a box with a label that marks an area of the diagram.

  1. Click an empty spot of the diagram, where the callout or the shape should go.
  2. Choose Diagram → Create Callout, or Diagram → Create Shape → Shape.
  3. Type the text. For a shape, also choose the Shape, such as Rectangle or Ellipse, and the Color.
  4. Press OK.
A DbSchema diagram with the callout An order holds one row per product, and an ellipse shape named Catalog next to the products and categories tables

If a table or a group is selected when you create a callout, the callout points at it. You can also right-click a table or a group and choose Set Callout, to create a callout that points at it.

The Create Shape menu also holds Process, Decision, Start/End and the other shapes of a flow diagram. A flow diagram shows the steps of a process next to your tables. Flow Diagrams explains them.

Arrange the tables automatically

Auto Arrange Tables places the tables of the diagram according to their foreign keys. Use it after you load a large schema, when the tables overlap.

  1. Choose Diagram → Auto Arrange Tables.
  2. Choose Arrange Only to move the tables, or Group and Arrange to also put related tables into groups.
The Auto-place Tables dialog of DbSchema with the choices Group and Arrange and Arrange Only, and the buttons Arrange Only, Group and Arrange and Cancel

If you don't like the result, choose Edit → Undo, or press Ctrl+Z. Undo brings back the positions of every table in one step.

DbSchema shows this dialog only on a diagram without groups. If the diagram has a group, DbSchema arranges the tables at once, without making new groups.

To arrange the tables of one group only, right-click the group and choose Auto Arrange Tables. DbSchema then arranges the tables of that group without asking.

Show the column data types

By default, a table on the diagram shows the column names and an icon for each data type.

Choose View → Diagram Display → Column Data Type to display the data type next to each column, instead of the icon. You can also use the Type button of the toolbar. Choose Column Data Type again to hide the data types.

The countries, addresses and customers tables on a DbSchema diagram, with data types such as char(2), varchar(120) and integer next to the column names, and addresses covering the right edge of countries

The tables become wider and may overlap. In the picture, addresses overlaps countries. Drag a table header to move the table.

View → Diagram Display holds more options for what the diagram shows:

ItemWhat it shows
Schema Name in Table HeaderThe schema name in each table header
Page BordersThe borders of the printed pages
Dot GridThe dots in the diagram background
Deduced Foreign KeysDashed lines for the joins in view queries

Each option applies to the open diagram, except Dot Grid, which applies to every diagram.

To color a table, right-click its header and choose Change Color, as Color a table shows. To draw the foreign key lines in another notation, such as Barker or Idef1x, see Change the notation.

Zoom in and out

Menu itemKeys
View → Zoom InCtrl++
View → Zoom OutCtrl+-
View → Zoom 100%Ctrl+0
View → Choose Zoom...Ctrl+9, which opens a zoom slider

You can also hold Ctrl and turn the mouse wheel over the diagram.

The Main Diagram of DbSchema zoomed out, so every table of the shop design fits in the window

Export the diagram as an image

  1. Open the diagram you want to export.
  2. Choose File → Export As... → Diagram Image.
  3. Choose PNG Image, GIF Image, JPG Image or SVG Image.
  4. Choose where to save the file.

The exported image includes the entire diagram, even the parts outside the window. The image uses light colors, even when DbSchema uses a dark theme.

The Main Diagram of the shop design exported from DbSchema as a PNG image, with all eleven tables on a white background

To publish an interactive diagram with the details of every table, generate the HTML5 documentation instead. It needs DbSchema Pro.

Common problems

Auto Arrange moved the tables I had placed by hand

Choose Edit → Undo right after Auto Arrange Tables. It brings back every table to its old position.

To arrange only some tables, put them into a group. Then choose Auto Arrange Tables from the group's right-click menu, as Arrange the tables automatically shows. The other tables stay in place.

Click the arrow icon at the right of a foreign key column and choose Add All, as Add the related tables shows. In the New Diagram dialog, Select ... selects the parent or child tables of the tables you included.

Next steps