Export
Download an ER diagram as schema code, SQL for five databases, a Mermaid file or a picture, and see what each file holds.
You can download any ER diagram as schema code, as SQL for five databases, as a Mermaid file or as a picture. This page lists each one and what it holds.
Export a file
Open Export at the top right of the diagram. Pictures are under Image, and text files under Code:
| Menu item | What you get |
|---|---|
| SVG | An .svg picture of the diagram. |
| PNG | A .png picture of the diagram. |
| Copy as image | The picture, copied to your clipboard. |
| Schema code | A .dbml file with the diagram in schema code. |
| SQL for PostgreSQL | A .sql script that creates the schema in PostgreSQL. ⇧ ⌘ E (Shift Ctrl E on Windows and Linux) downloads it without opening the menu. |
| SQL for MySQL | A .sql script for MySQL. |
| SQL for SQL Server | A .sql script for SQL Server. |
| SQL for SQLite | A .sql script for SQLite. |
| SQL for Oracle | A .sql script for Oracle. |
| Mermaid file | A .mmd file for Mermaid. |
| Copy Schema code | The schema code, copied to your clipboard. |
The size and theme of a picture work as in every kind. See Export.
At the bottom of the menu, View PostgreSQL SQL…, View MySQL SQL…, View SQL Server SQL…, View SQLite SQL…, View Oracle SQL… and View Mermaid… show the text read only, with a button to copy it.
Migration SQL and joins
Two more kinds of SQL come from elsewhere in the app:
- Copy migration SQL copies the script that takes a database from an earlier version of the schema to now. Open Version history, point to the version and choose Compare with now.
- Copy JOIN copies a query that joins two tables along their relationships. Select the two tables, turn on Trace and choose Copy JOIN in its bar.
Both are written for the schema's database, which you set under Database in the canvas menu.
What the SQL holds
Each SQL script creates the tables with their keys, defaults, checks and indexes. It inserts the tables' sample rows (records). It adds the foreign keys last, so the script runs whatever order the tables are in.
SQLite can't add a foreign key to a table that already exists. So in SQLite, the foreign keys go inside each table instead.
A few common types are written the way each database spells them. For example:
uuidbecomeschar(36)in MySQL anduniqueidentifierin SQL Server.- Oracle writes whole numbers as
NUMBER(10), text asVARCHAR2orCLOB, and booleans asNUMBER(1).
Enums become a type of their own in PostgreSQL, and an ENUM column in MySQL. In SQL Server, SQLite and Oracle, they become a text column with a check.
A many-to-many relationship becomes a junction table named after both tables, such as orders_products. Its key is a column pointing at each side (order_id, product_id).
An index on an expression, such as lower(email), is written the way each database takes it. SQL Server can't index an expression, so there the script has a comment saying to index a computed column instead.
An index's type, such as hash, is written for PostgreSQL and MySQL. Oracle has no ON UPDATE for a foreign key. The message as the file downloads counts what a script can't say.
What the Mermaid file holds
The Mermaid file has the tables, their columns and keys, and the relationships. Enums, groups, indexes and notes are left out.
A table's colour is written as the entity's style line, which Mermaid 11.5 and newer draws. The app reads it back when you import or paste the file. Mermaid has no colour for a relationship, a group, a note or an enum.
Colours that don't fit
The SQL scripts have no colours at all. When a file can't hold some colours, the app says so as the file downloads, and above the text in View…. For example: "SQL has no colours; 3 were left out." or "Mermaid has no relationship and group colours; 2 were left out."
A .dbml download can't hold an enum's colour either. See Colours.