ER Diagram to SQL

Turn a Mermaid ER diagram into CREATE TABLE statements for PostgreSQL, MySQL, SQL Server or SQLite, with primary keys, foreign keys and join tables worked out from the relationships. Free, and it runs in your browser.

Only have a picture of the diagram? Convert the image to Mermaid first, then click SQL.

Mermaid erDiagram
Paste a Mermaid erDiagram to generate SQL
Diagram

Frequently asked questions

How do I convert an ER diagram to SQL?

Paste your Mermaid erDiagram code into the editor and pick a database. The CREATE TABLE statements appear as you type: one table per entity, a column per attribute, primary and unique keys from PK and UK, and foreign keys from the relationship lines. Copy the SQL or download it as a .sql file.

I only have a picture of the ER diagram. Can I still get SQL?

Yes. Upload the image to the Image to Mermaid app, which reads it with AI and returns erDiagram code (3 free conversions, then credits). Click SQL above the code and it opens here, ready to convert.

How are relationships turned into foreign keys?

One-to-many puts a foreign key on the many side, reusing a column you already declared (customer_id or customerId) or adding one. It is NOT NULL unless the parent end is zero-or-one. One-to-one adds UNIQUE to that foreign key. Many-to-many adds a join table whose primary key is both foreign keys.

Which databases are supported?

PostgreSQL, MySQL, SQL Server and SQLite. Types are mapped for each one: string becomes VARCHAR(255) or NVARCHAR(255), datetime becomes TIMESTAMP, DATETIME or DATETIME2, boolean becomes BIT on SQL Server, and so on. Names that are reserved words, like ORDER, are quoted the way each database expects.

What if an entity has no primary key?

An id column is added as its primary key, and a note under the SQL says so. If the entity already has a column called id, that column becomes the key instead.

Is it free? Is my schema uploaded?

It is free with no signup, and the conversion runs entirely in your browser: your diagram is not sent to our servers.

Other converters