From ER Diagram to SQL with Dia
Dia Diagram Editor is a free, open-source project by the GNOME community. This site is an independent community resource — we are not affiliated with the GNOME Dia project.
Honest answer first: Dia does not generate SQL by itself. It’s a drawing tool — it won’t turn your ER diagram into CREATE TABLE statements on its own. But the toolchain exists: draw the ERD with Dia’s Database shapes, then run a converter. Here’s the practical path, including which tools actually still work.
Step 1: Draw the ERD properly
Use the Database sheet (File → Sheets and Objects → tick Database), not generic boxes. The Database table objects carry real structure — table name, columns, types, keys — which is what converters read. Generic boxes look the same but contain no data. See our ER diagram tutorial for the drawing part.
Step 2: Convert with parsediasql (recommended)
Parse::Dia::SQL is a Perl module that reads Dia files and emits SQL, and it’s still actively packaged — Ubuntu ships it as libparse-dia-sql-perl (Universe), including the parsediasql command-line tool:
sudo apt install libparse-dia-sql-perl parsediasql schema.dia > schema.sql
It parses the Database shapes in your .dia file and generates CREATE TABLE statements. Review the output before running it anywhere important — generated SQL is a starting point, not a reviewed migration.
Alternatives (older, use with care)
- dia2sql (SourceForge) — the original Perl script; old, processes EPS exports, largely superseded by parsediasql.
- dia2sql (GitHub, superlinux) — a small C++ tool:
dia2sql input.dia output.sql, reads Database shapes directly. Community-maintained; test on a copy first. - XSLT route — Dia files are XML, so XSLT stylesheets can transform them; some older guides use this. Only worth it if you enjoy XSLT.
When to skip Dia entirely
If your goal is “design database → get SQL” as a daily workflow, a dedicated data-modeling tool (dbdiagram.io, DBeaver’s ERD, MySQL Workbench) generates better DDL with less friction. Dia’s strength here is documenting a schema beautifully — the SQL export is a bonus, not the main event.
FAQ
Can Dia generate SQL natively?
No. You need an external converter like parsediasql. Dia’s job is the diagram; the converter reads the Database shapes’ structured data.
Which shapes must I use for conversion to work?
The Database sheet’s table objects — with columns, types, and keys filled in. Generic boxes and UML classes won’t convert.
Does parsediasql support my database?
It generates fairly standard SQL. Dialect-specific features (Postgres enums, MySQL engine clauses) usually need manual finishing.
The converter can’t read my .dia file. Why?
Make sure you used Database shapes (not lookalikes) and saved normally. Some very old tools expect uncompressed XML — parsediasql handles standard .dia files directly.
Is the generated SQL safe to run in production?
Run it in a scratch database first, diff it against your expectations, then adopt it into your migration tooling. Never blind-run generated DDL on production.
