# Export SQL / Generate DDL

> Generate DDL from your Schemity ERD. Export CREATE statements for PostgreSQL, MySQL, SQL Server, or SQLite to turn your diagram into runnable SQL - even offline.

Source: https://schemity.com/doc/export-sql-ddl/

A diagram is most useful when it can become real tables. Schemity exports your ERD as **DDL** - the `CREATE` statements that build the schema in your database.

## What export formats does Schemity support?

From the export menu you can save the current diagram as:

- **PNG** - a raster image with transparency.
- **JPEG** - a smaller raster image.
- **SVG** - vector output with selectable text that scales infinitely, and opens as editable artwork in Figma, Affinity Designer, Illustrator and Inkscape.
- **SQL** - a plain-text file of all the CREATE statements for the whole diagram.
- **DBML** - a schema definition file for dbdiagram.io and the wider DBML toolchain.
- **Mermaid** - an erDiagram file that Mermaid-enabled platforms render as a diagram.
- **Data dictionary** - the schema as a document in HTML, Markdown, or Excel. See [Data Dictionary Export](https://schemity.com/doc/data-dictionary/).

## How do I generate DDL from my ERD?

Choose the **SQL** export to generate engine-aware DDL for the connection's database type, emitting:

- `CREATE TABLE` statements with columns, types, and nullability
- Primary keys, including composite keys
- Foreign keys that match your relationships
- Unique and check constraints, and indexes

[Virtual relations](https://schemity.com/doc/virtual-relations/) are left out of SQL and DBML exports: they document dependencies the database does not declare, and exporting one would turn documentation into a real foreign key.

## Can I get the SQL or DBML for just part of the diagram?

Yes. Right-click an entity, a multi-selection, or a legend and choose **Get SQL** or **Get DBML** (`Cmd/Ctrl+Shift+G`). A preview opens with a click-to-copy label. The DBML snippet drops any reference whose other end is outside the selection, so it always parses on its own.

## Does the generated SQL match my database engine?

The output respects your target engine. Data types, default-value syntax, and constraint formatting follow PostgreSQL, MySQL, SQL Server, or SQLite conventions, so the SQL is ready to run on the database you actually use.

## Can I export SQL without a live connection?

DDL generation does not need a live connection. Even a design-only diagram, with no database behind it, exports a complete SQL script you can run elsewhere - a fresh environment, a test database, or a new service.

## Can I export my ERD as a Mermaid diagram?

Yes. Choose the **Mermaid** export to save the diagram as a Mermaid `erDiagram` file. Paste its content into a fenced ` ```mermaid ` block in any Mermaid-enabled platform - GitHub, GitLab, Notion, Obsidian - and the platform renders the schema as a vector diagram, straight from the markdown. Because the diagram is text inside the document, schema updates show up as a readable diff instead of a replaced image.

Note that Mermaid carries entities and relationships, not your canvas layout - the renderer arranges the diagram itself. When the arrangement matters, export **SVG** instead.

## Should I commit the generated SQL to Git?

Commit the generated SQL alongside the [JSON diagram](https://schemity.com/doc/version-control-git/). Reviewers then see both the visual change and the exact SQL in the same pull request.

## Next

Evolve an existing database safely with [Migration SQL Diff](https://schemity.com/doc/migration-sql-diff/).
