Import a schema
Bring a schema in from a SQL, Mermaid or DBML file, or paste one into the code pane.
You can start an ER diagram from a SQL script, a Mermaid file or a DBML file. To download a diagram as SQL, schema code, Mermaid or a picture, see Export.
Import a file
- In the Diagrams panel, open New diagram (the + button).
- Choose Import SQL, DBML or Mermaid file….
- Pick a
.sql,.dbml,.mmd,.mermaid,.mdor.txtfile.
The file becomes a new diagram, named after its Project or the file.
The app reads the file by what's in it:
- A
.sqlfile, or another file withCREATE TABLEin it, is read as SQL. - A file that starts with
erDiagramis read as Mermaid. So is theerDiagramin a ```mermaid block of a.mdfile. - Anything else, such as a
.dbmlfile, is read as schema code, which is DBML.
A file with no tables in it isn't imported, and the message says so. If the SQL can't be read, the message says why, with the line number when there is one.
From SQL
Scripts for PostgreSQL (a pg_dump too), MySQL, SQL Server, SQLite and Oracle all read. These come in:
- tables, and columns with their types as written;
- keys, and auto-increment (
SERIAL,IDENTITY,AUTO_INCREMENT,AUTOINCREMENT, anextvaldefault); - defaults, checks, and indexes with their method (
USING hash); - foreign keys, enums and comments.
When the file has things a schema can't hold, the message says what was left out. That covers views, sample rows (INSERT), full-text indexes, a partial index's WHERE, and an index's INCLUDE columns. It also covers MySQL's ON UPDATE CURRENT_TIMESTAMP, and the names of constraints on a column other than a foreign key's.
From Mermaid
Each entity becomes a table, and each relationship a line between columns, named with its label (places).
Entities with no attributes, as in Mermaid's own examples (CUSTOMER ||--o{ ORDER : places), get an id key. They also get a column for each relationship they hold, named after the table it points at (customer_id). The message lists these columns, since the file didn't have them.
An entity with attributes gets no added columns. A relationship that none of its attributes carries is left out, and the message names it.
Cardinality can be symbols or words, with to or optionally to between them:
- symbols:
||,|o,}o,}|; - words:
only one,zero or one,one or more,zero or more,1,1+,0+,many(0),many(1).
An end of exactly one (||, only one, 1) makes the column that points at it required. "One or more" comes in as many, because no schema constraint can make a row have at least one row pointing at it.
An alias such as p["Customer Account"] makes the table Customer Account, with p as its alias. Relationships written with p still find it.
A table's colour comes from the entity's style line.
Paste SQL or Mermaid
You can also paste a SQL script, or Mermaid erDiagram text, into the Schema code pane. The app converts it to schema code and draws it. It says what it left out, as an import does.
If you type the text instead of pasting it, the pane offers a Convert from SQL or Convert from Mermaid button.