Use the SQL plugin to create an entity relationship diagram

This plugin should be used as-is, as an unsupported example for developers.

Insert SQL code using the SQL plugin to automatically generate entity shapes, including their attributes, as well as their primary and foreign keys. To complete your entity relationship diagram, connect the entities together and set the connector ‘arrows’ to describe their relationships.

Insert SQL code to create your ER diagram automatically using the SQL plugin at draw.io

Load the SQL plugin

Create an ER diagram from SQL code

As SQL and MySQL are the most popular languages used to program and work with relational database systems, draw.io has made it easy to automatically create your diagrams from your code.

  1. Click Arrange > Insert > From SQL.
  2. Copy and paste your SQL code into the dialog, then click Insert MySQL or Insert SQL Server, whichever matches the code you just pasted.
    Insert SQL code then select which SQL it is to create an ER diagram automatically
  3. Your SQL code is converted into entities containing the attributes, as well as the primary and foreign keys your code defines.
  4. Connect the entities and choose the ‘arrow’ shape that defines the relationship.
    Entity shapes are automatically created based on your SQL code - draw connectors to finish your ER diagram

Tip: To see the various entity relationship styles, enable the Entity Relation shape library (via More Shapes in the left panel), then hover over the various connector shapes to show their descriptions.
Hover over connector shapes in the Entity Relation library to see them more clearly

Permanently load the plugin

If you want to always use the sql plugin, add it to the plugins list so it will be loaded each time you create or edit a diagram.

  1. From the menu, select Extras > Plugins.
    Open the plugins list
  2. Click Add.
    Add a new plugin
  3. Select sql in the drop-down list of built-in plugins, then click OK.
    Add the SQL plugin
  4. Click Apply.
    Add the SQL plugin

Reload your browser tab to load the plugin into the diagram editor.

Note: Plugins work with the web version of draw.io (app.diagrams.net) or our Docker image if you want to run your own server. They do not work with draw.io for Confluence/Jira or with draw.io Desktop.