Database diagrams
In the Database Explorer, right-click a database object and select Diagrams | Show Diagram
This functionality relies on the Diagrams plugin, which is bundled and enabled in DataGrip by default. If the relevant features are not available, make sure that you did not disable the plugin.
Press CtrlAlt0S to open settings and then select Plugins.
Open the Installed tab, find the Diagrams plugin, and select the checkbox next to the plugin name.
Database diagrams graphically show the structure of the database and relations between database objects. You can generate a diagram for a data source, a schema, or a table. To create relations between database objects, consider using primary and foreign keys.
The following video gives a short overview of diagrams in DataGrip.
note
In the video, the DataGrip user interface is Classic UI. Starting from version 2023.1, the New UI is available. For more information about the New UI, refer to the corresponding topic.
You can save the generated diagrams in two formats: UML and PNG. The UML format is an internal format developed specifically for DataGrip. It is not supported by other products. If you want to share the created diagram, consider using PNG.
Also, you can build execution plans. An execution plan is a set of steps that were used to access data in a database. For more information about creating an execution plan, refer to Visualize a query plan.
In the Database Explorer (View | Tool Windows | Database Explorer) , right-click a database object and select Diagrams | Show Diagram.
To pan and zoom the diagram, use your touchpad, scroll bars or the mouse wheel for vertical scrolling and Shift + mouse wheel for horizontal scrolling. You can also use Shift + mouse wheel for zooming.
To use the magnifier tool, keep the Alt key pressed and hover over the desired areas of the diagram. Use the mouse wheel to extra zoom the diagram area within the magnifier tool.
Generate a diagram. For more information about generating a diagram, refer to Generate a diagram for a database object.
Click the Comments button ().
In the Database Explorer (View | Tool Windows | Database Explorer) , right-click an object and select Tools | Set Color.
Select a color and click OK. Refresh the diagram to apply the color by clicking the Refresh button ().
Open settings by pressing CtrlAlt0S and navigate to Editor | Color Scheme | Diagrams. .
Click Edges//Generalization edge.
Click the color picker near the Foreground checkbox.
In DataGrip, you can export a diagram in various formats to a file, to clipboard, and open it in a web editor. You can also print a diagram and save it as an image. To do that, use the corresponding actions in the context menu of your diagram.
To export your diagram to a third-party editor in web browser, right-click the diagram, navigate to Export Diagram | Open in Web Editor, and select the editor.
Alternatively, click the Export Diagram button () on the diagram toolbar, and select the editor in the corresponding submenu.
The supported editors are as follows:
To copy your diagram to clipboard, right-click the diagram, navigate to Export Diagram | Copy to Clipboard, and select the format.
Alternatively, click the Export Diagram button () on the diagram toolbar, and select the format in the corresponding submenu.
The supported formats are as follows:
Mermaid
classDiagram
{...}PlantUML
@startuml
{...}Graphviz DOT
digraph "sakila" {
{...}Graphviz DOT with Positions
digraph "sakila" {
{...}
To export your diagram to a file, right-click the diagram, navigate to Export Diagram | Export to File, and select the format.
Alternatively, click the Export Diagram button () on the diagram toolbar, and select the format in the corresponding submenu.
The supported formats are as follows:
YEd .graphml
JGraph .drawio
Graphviz .dot
Graphviz .dot with Positions
Mermaid .md
PlantUML
IDEA .uml: The UML format
is an internal format supported only by DataGrip. To open the saved diagram, drag the UML file to the editor.
To export your diagram as an image in PNG format, right-click the diagram and select Export Diagram | Export to Image.
Alternatively, click the Export Diagram button () on the diagram toolbar, and select Export to Image.
The Analyze Graph action group lets you analyze the graph in various ways such as perform auto clusterization, measure the node centrality, search cycles, filter path between two nodes, and so on.
Most of the time, generated diagrams are big and complicated. Typically, you want to concentrate only on the specific part of the diagram. DataGrip lets you filter paths between two diagram elements.
In the diagram editor, select two nodes on which you want to focus and right-click one of them to open the context menu.
From the context menu, select Analyze Graph | Focus On Paths Between Two Nodes.
note
If you want to focus not only on just two nodes, but on how the selected node is connected with its neighbors, select the Focus on Node Neighborhood option from the context menu.
In the dialog that opens, select additional options if needed and click Find.
DataGrip displays connections associated only with the selected nodes.
You can use this action to identify the important nodes in the graph.
In the diagram editor, right-click anywhere in the editor to open the context menu.
From the context menu, select Analyze Graph | Measure Centrality.
In the dialog that opens, select additional options if needed and click Measure.
The node "importance" is expressed via fractional value from 0.0 to 1.0 measurement, and the brightest node selection should be explored first.
tip
Press Ctrl0Z to cancel the actions.
Possible icon combinations for columns in diagrams:
Icon | Foreign key | Primary key | Indexed | NOT NULL |
---|---|---|---|---|
To configure the default visibility settings and layout for diagrams, Open settings by pressing CtrlAlt0S and navigate to Tools | Diagrams. .
Select the checkboxes next to the elements to be shown on diagrams.
Item | Description |
---|---|
Show Difference | |
Details | If this checkbox is selected, all the specified details of the elements will be shown in the UML class diagram for a revision. If this checkbox is not selected, only node elements will be included in the diagram. |
Database Schema Diagram | |
Key columns | For the primary key columns to be shown when a diagram opens, select this checkbox. When viewing a diagram in the editor, use on the toolbar to show or hide the corresponding columns. |
Columns | For the columns other than the primary key columns to be shown when a diagram opens, select this checkbox. When viewing a diagram in the editor, use on the toolbar to show or hide the corresponding columns. |
Graphical Explain Plan | |
Attributes | Toggles the display of query attributes on a query map. These attributes can be a number of rows, index names, or any other additional information about the query. Enabled Disabled |
Item | Description |
---|---|
Default layout | Select the desired layout from the Default layout list. Node elements in newly created diagrams will be arranged according to the selected layout. |
Default scope | Select scope from the Default scope list. Specifying a scope helps you avoid showing in diagram the unnecessary hierarchies. You can define scopes for your project in the Scopes page of the Settings (CtrlAlt0S) dialog. |
Fit content after layout | If this checkbox is selected, then after applying a layout selected on the diagram context menu, all diagram elements will be resized to fit into the current diagram area. In diagram, use the toolbar button. |
Do relayout when new elements were added | If this checkbox is selected, diagram layout will be performed automatically after adding new elements. |
Use the diagram editor toolbar to quickly access actions and the context menu to manage the displayed diagram.
Item | Description |
---|---|
Click this button to show primary key columns in the diagram. | |
Toggles the display of the following:
| |
Click this button to hide or show virtual foreign keys in the diagram. | |
Click this button to hide or show comments in the diagram. | |
Click this icon to increase the scale of the diagram. Alternatively, press NumPad +. | |
Click this icon to decrease the scale of the diagram. Alternatively, press NumPad -. | |
Click this icon to restore the actual size of the diagram. | |
Click this icon to make the contents fit into the current diagram size. | |
Click this icon to apply the current layout, selected from the Layout node of the diagram context menu. | |
Click this icon to scale the diagram to the edges of the window. | |
Click this icon to copy the diagram into the clipboard. | |
Click this icon and then select any diagram area with the mouse: the selected area will be copied into the clipboard. | |
Click this icon to export a diagram using various formats, which are compatible with third-party tools, to a file, to an image, or open the diagram in the browser. You can select and configure the following options:
| |
Click this button to refresh the whole diagram. | |
Click this button to open the Diagram settings where you can configure additional options. |
The table below contains commands that are not available from the toolbar.
Item | Description |
---|---|
Selected Element Actions | Use this option to open a list of actions that is applied to a selected element in the diagram. You can select actions to copy an element, show its definitions and documentation, use the Navigate actions, and so on. |
Content | Use this option to open a list of actions that help you to add new notes, show and hide attributes.
|
Delete | Deletes the selected diagram. |
Analyze Graph | Use this node to select one of the commands to analyze a diagram. You can check the graph characteristics, change the focus of the graph, measure graph centrality, and so on. |
Layout | Select the desired diagram layout from the submenu. |
Orientation | Provides you with the following orientation options: Bottom to Top, Top to Bottom, and so on. |
Apply Current Layout | Applies the current layout, selected from the Layout node of the diagram context menu |
Auto Route Edges | Scales the diagram content to the edges of the diagram window. |
Appearance | Manages the way the diagram is presented by showing the grid, edge labels, bridges. Allows you to merge edges and select edge shapes. |
Behavior | Use this option to select commands related to the diagram behavior sucha as aligning elements against the grid, showing structure view for the selected node, or fitting the content after the layout. |
Copy Diagram to Clipboard | Click this icon to copy the diagram into the clipboard. |
Copy Selection to Clipboard | Click this icon and then select any diagram area with the mouse: the selected area will be copied into the clipboard. |
Export Diagram | Use this option to export a diagram using various formats, which are compatible with third-party tools, to a file, to an image, or open the diagram in the browser. You can select and configure the following options:
|
Thanks for your feedback!