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 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.
- Choose Diagram → New Diagram, or press Ctrl+L.
- Type a Name.
- Pick a table in the list on the left and press Include >>.
- Press Ok.
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 ... item | Tables it selects |
|---|---|
| All | Every table of the schema |
| Tables Not in Any Diagram | The 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 item | What it does |
|---|---|
| New Empty Diagram (Ctrl+Shift+L) | Opens a diagram with no tables |
| Duplicate Diagram | Copies the open diagram |
| Diagram Properties | Opens 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.
Add the related tables
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.
- Drag a table, such as
orders, from the tree on the left onto the diagram. - Click the arrow icon at the right of a column, such as
order_id. - 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.
- Click the first table header, then Ctrl+click the other tables.
- Choose Diagram → Create Group of Tables, or Table → Create Group of Tables in the toolbar.
- 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.
- Click an empty spot of the diagram, where the callout or the shape should go.
- Choose Diagram → Create Callout, or Diagram → Create Shape → Shape.
- Type the text. For a shape, also choose the Shape, such as Rectangle or Ellipse, and the Color.
- Press OK.
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.
- Choose Diagram → Auto Arrange Tables.
- Choose Arrange Only to move the tables, or Group and Arrange to also put related tables into groups.
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 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:
| Item | What it shows |
|---|---|
| Schema Name in Table Header | The schema name in each table header |
| Page Borders | The borders of the printed pages |
| Dot Grid | The dots in the diagram background |
| Deduced Foreign Keys | Dashed 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 item | Keys |
|---|---|
| View → Zoom In | Ctrl++ |
| View → Zoom Out | Ctrl+- |
| 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.
Export the diagram as an image
- Open the diagram you want to export.
- Choose File → Export As... → Diagram Image.
- Choose PNG Image, GIF Image, JPG Image or SVG Image.
- 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.
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.
How do I add all the tables related to a table?
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.