Skip to main content

SQL Export

Export your schema as production-ready CREATE TABLE statements.

Steps

  1. Click Export in the top-right of the ERD panel
  2. Select SQL
  3. Choose your target dialect: PostgreSQL, MySQL, SQLite, or MSSQL
  4. Click Download — a .sql file downloads

What's included

  • CREATE TABLE statements for all tables
  • PRIMARY KEY constraints
  • FOREIGN KEY constraints with ON DELETE / ON UPDATE rules
  • UNIQUE constraints
  • NOT NULL constraints
  • DEFAULT values
  • CREATE TYPE (enums — PostgreSQL only)
  • AUTO_INCREMENT / SERIAL / IDENTITY for auto-increment PKs

PostgreSQL example

CREATE TYPE carbon_tier AS ENUM ('A', 'B', 'C', 'D');
CREATE TYPE order_status AS ENUM ('pending', 'confirmed', 'processing', 'shipped', 'delivered', 'cancelled');

CREATE TABLE suppliers (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
carbon_tier carbon_tier NOT NULL DEFAULT 'C',
country VARCHAR(100),
is_active BOOLEAN NOT NULL DEFAULT TRUE,
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);

CREATE TABLE products (
id SERIAL PRIMARY KEY,
supplier_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
sku VARCHAR(100) NOT NULL UNIQUE,
carbon_intensity_score DECIMAL(5,2) NOT NULL DEFAULT 0,
unit_price DECIMAL(10,2) NOT NULL DEFAULT 0,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
FOREIGN KEY (supplier_id) REFERENCES suppliers(id) ON DELETE RESTRICT
);

Running the exported SQL

The exported file can be run directly:

# PostgreSQL
psql -U username -d database_name -f schema.sql

# MySQL
mysql -u username -p database_name < schema.sql