Export ERD to SQL CREATE TABLE Statements

How to export your Entity-Relationship Diagram as executable SQL DDL. Covers CREATE TABLE generation, foreign key constraints, and primary key declarations.

Export & Integration

Detailed Explanation

From Visual Design to Executable SQL

One of the most powerful features of an ERD editor is the ability to generate SQL directly from your visual diagram. This bridges the gap between design and implementation — you design visually, and the tool produces the DDL (Data Definition Language) statements you need to create the actual database tables.

What Gets Generated

The ERD editor generates the following SQL elements from your diagram:

ERD Element SQL Output
Entity (table) CREATE TABLE table_name (
Column column_name TYPE [constraints]
Primary key PRIMARY KEY (column_name)
NOT NULL Column without NULL / with NOT NULL
UNIQUE UNIQUE constraint on the column
Foreign key FOREIGN KEY (col) REFERENCES other_table(col)

Example Output

Given an ERD with users and posts entities connected by a one-to-many relationship:

CREATE TABLE users (
  id SERIAL NOT NULL,
  username VARCHAR(255) NOT NULL UNIQUE,
  email VARCHAR(320) NOT NULL UNIQUE,
  created_at TIMESTAMP NOT NULL,
  PRIMARY KEY (id)
);

CREATE TABLE posts (
  id SERIAL NOT NULL,
  user_id INT NOT NULL,
  title VARCHAR(255) NOT NULL,
  body TEXT,
  published_at TIMESTAMP,
  FOREIGN KEY (user_id) REFERENCES users(id),
  PRIMARY KEY (id)
);

Table Order Matters

The generated SQL respects dependency order. Tables that are referenced by foreign keys should be created first. If posts references users, then the CREATE TABLE users statement comes before CREATE TABLE posts.

Export Options

The ERD editor provides three ways to get your SQL:

  1. SQL button: Downloads a .sql file containing all CREATE TABLE statements
  2. Copy SQL button: Copies the SQL to your clipboard (or press Ctrl+Shift+C)
  3. SQL Preview panel: Shows the live SQL output below the canvas as you edit

Next Steps After Export

Once you have the SQL, you can:

  • Execute it directly against PostgreSQL, MySQL, or SQLite
  • Feed it into a migration tool (Flyway, Liquibase, Prisma Migrate)
  • Convert it to an ORM schema using the SQL to Prisma converter
  • Version-control it in your repository alongside application code

Use Case

You have finished designing your database schema visually and need to create the actual tables in your database. The SQL export gives you production-ready DDL statements that you can execute directly or incorporate into your migration workflow.

Try It — ERD Editor

Open full tool