SQL from ERD

The entity-relationship diagram can be turned into a SQL script. The ERD tool can generate create scripts for each entity and relationship in the diagram or only for the selected part. You can transform ERD entities to database tables very easily.

How to Generate SQL Script for the ER Diagrams?

You can generate the SQL CREATE and INSERT scripts for the chosen ER diagrams in your project very easily.

First, open an existing project or draw an ER diagram in a new project. Then switch to the Process tab in the ribbon and click on the Source Code button (in the Generation group). Source Code Generation dialog will show.

Ribbon/Process/Generation/Source Code - Generate Source Code
Ribbon/Process/Generation/Source Code - Generate Source Code

Check all the diagrams, which you want to generate scripts for, in the project tree panel (in the left part of the window).

In the General tab, choose SQL DDL from the Language dropdown and SQL DDL from the Template dropdown. Set the Output directory where all the generated scripts will be saved.

If you do not want to have a script for each table in a separate file, check the One file per diagram option.

SQL Script Generation Dialog
SQL Script Generation Dialog

If everything is set by your requirements, click on the Generate button. The script generation will start.

The script generator creates:

  • SQL CREATE scripts for tables defined by entities
  • SQL INSERT scripts for data rows defined in enumeration entities.

How to Generate Change Scripts from an ER Diagram?

Software Ideas Modeler's ERD tools can help you also in the case when you want to generate change scripts for an existing database. It does not matter whether you model it completely in Software Ideas Modeler or it existed before. If you do not have an ERD model of the database yet, you can import it. The next steps are common for an ERD model drawn using Software Ideas Modeler and for an imported ERD model.

Switch to Review tab in the ribbon and click on the Track Changes button.

Ribbon/Review/Change Tracking/Track Changes button
Ribbon/Review/Change Tracking/Track Changes button

Adjust the ERD model as you want - you can add attributes, change them, add new entities, etc.

When you are finished with the changes - in the General tab, choose SQL DDL from the Language dropdown and SQL DDL - Changes from the Template dropdown. Adjust other settings you need - Output, One file per diagram, or Encoding. Then click on the Generate button. The scripts will be generated.

The script generator creates:

  • SQL CREATE scripts for new entities
  • SQL ALTER scripts for changed entities
  • SQL DROP scripts for deleted entities
  • SQL INSERT scripts for new data rows
  • SQL UPDATE scripts for changed data rows
  • SQL DELETE scripts for removed data rows

Generating SQL Script for Selected ERD Entities

If you want to quickly generate a SQL script only for some entities, you can use the Generation sidebar. Open Generation sidebar (View / Window / Sidebars / Generation), choose SQL DDL in the first dropdown in the sidebar and also in the second dropdown, change Generate From option to Selected Elements and click on Generate button. The script will appear in the text box below.

Generation Sidebar - Generate SQL Script for Selected Entity
Generation Sidebar - Generate SQL Script for Selected Entity

New Comment

Comment