Generate SQL from ERD
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 for 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.
Check all the diagrams, for which you want to generate scripts, 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.
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 if 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 the Review tab in the ribbon and click on the 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.
ERD to SQL
The script generator turn your ER diagrams to SQL - it produces:
- 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 the 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.