Export
Learn how to export production-ready SQL (DDL) from your database diagrams in StackRender. Generate clean SQL scripts for your preferred database dialect and use them to deploy or recreate your database schema anywhere.

Export SQL from StackRender
To export the generated SQL from your diagram:
- In the Diagram Editor, head to
File → Export SQL. - The Export SQL dialog will appear.
- Review the generated SQL script.
- Click Copy and use it to deploy your database schema.
StackRender automatically generates well-structured DDL statements based on your diagram configuration.
Example Generated SQL
Below is an example of SQL generated by StackRender:
CREATE TABLE "products" (
id SERIAL NOT NULL PRIMARY KEY,
vendor_id INTEGER NOT NULL,
category_id INTEGER NULL,
name TEXT NOT NULL,
description TEXT NULL,
price NUMERIC(10, 2) NOT NULL,
stock_quantity INTEGER NOT NULL,
sku TEXT NULL UNIQUE,
created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX "products_name_index" ON "products" ("sku", "name");
CREATE TYPE "payments_payment_status_enum" AS ENUM('unpaid', 'paid', 'refunded');
CREATE TABLE "payments" (
id SERIAL NOT NULL PRIMARY KEY,
order_id INTEGER NOT NULL UNIQUE,
payment_date TIMESTAMPTZ NULL,
amount NUMERIC(10, 2) NOT NULL,
payment_method TEXT NULL,
transaction_id TEXT NULL UNIQUE,
payment_status payments_payment_status_enum NOT NULL DEFAULT 'unpaid',
created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TYPE "shipments_fulfillment_status_enum" AS ENUM(
'not_fulfilled',
'fulfilled',
'partially_fulfilled'
);
CREATE TABLE "shipments" (
id SERIAL NOT NULL PRIMARY KEY,
order_id INTEGER NOT NULL UNIQUE,
shipment_date TIMESTAMPTZ NULL,
tracking_number TEXT NULL UNIQUE,
carrier TEXT NULL,
fulfillment_status shipments_fulfillment_status_enum NOT NULL DEFAULT 'not_fulfilled',
created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE "order_items" (
id SERIAL NOT NULL PRIMARY KEY,
order_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
vendor_id INTEGER NOT NULL,
quantity INTEGER NOT NULL,
price_per_item NUMERIC(10, 2) NOT NULL,
subtotal NUMERIC(10, 2) NOT NULL
);
CREATE TABLE "product_images" (
id SERIAL NOT NULL PRIMARY KEY,
product_id INTEGER NOT NULL,
image_url TEXT NOT NULL,
alt_text TEXT NULL,
display_order INTEGER NULL
);
CREATE TABLE "carts" (
id SERIAL NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL UNIQUE,
created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE "reviews" (
id SERIAL NOT NULL PRIMARY KEY,
product_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
rating INTEGER NOT NULL,
comment TEXT NULL,
review_date TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE "cart_items" (
id SERIAL NOT NULL PRIMARY KEY,
cart_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
quantity INTEGER NOT NULL,
added_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TYPE "orders_currency_enum" AS ENUM('USD', 'EUR', 'GBP');
CREATE TYPE "orders_order_status_enum" AS ENUM(
'pending',
'processing',
'shipped',
'delivered',
'cancelled'
);
CREATE TABLE "orders" (
id SERIAL NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL,
order_date TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP,
total_amount NUMERIC(10, 2) NOT NULL,
currency orders_currency_enum NOT NULL,
order_status orders_order_status_enum NOT NULL DEFAULT 'pending',
shipping_address TEXT NULL,
billing_address TEXT NULL,
created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE "vendor_payouts" (
id SERIAL NOT NULL PRIMARY KEY,
vendor_id INTEGER NOT NULL,
payout_date TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP,
amount NUMERIC(10, 2) NOT NULL,
transaction_id TEXT NULL UNIQUE
);
CREATE TABLE "users" (
id SERIAL NOT NULL PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
email TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
first_name TEXT NULL,
last_name TEXT NULL,
shipping_address TEXT NULL,
billing_address TEXT NULL,
created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE "categories" (
id SERIAL NOT NULL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
description TEXT NULL
);
CREATE TABLE "vendors" (
id SERIAL NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
phone_number TEXT NULL,
address TEXT NULL,
created_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE "products"
ADD CONSTRAINT "fk_vendors_products" FOREIGN KEY (vendor_id) REFERENCES "vendors" (id);
ALTER TABLE "shipments"
ADD CONSTRAINT "fk_orders_shipments" FOREIGN KEY (order_id) REFERENCES "orders" (id) ON DELETE CASCADE;
ALTER TABLE "vendor_payouts"
ADD CONSTRAINT "fk_vendors_vendor_payouts" FOREIGN KEY (vendor_id) REFERENCES "vendors" (id);
ALTER TABLE "order_items"
ADD CONSTRAINT "fk_orders_order_items" FOREIGN KEY (order_id) REFERENCES "orders" (id) ON DELETE CASCADE;
ALTER TABLE "reviews"
ADD CONSTRAINT "fk_products_reviews" FOREIGN KEY (product_id) REFERENCES "products" (id) ON DELETE CASCADE;
ALTER TABLE "reviews"
ADD CONSTRAINT "fk_users_reviews" FOREIGN KEY (user_id) REFERENCES "users" (id);
ALTER TABLE "order_items"
ADD CONSTRAINT "fk_products_order_items" FOREIGN KEY (product_id) REFERENCES "products" (id);
ALTER TABLE "orders"
ADD CONSTRAINT "fk_users_orders" FOREIGN KEY (user_id) REFERENCES "users" (id);
ALTER TABLE "carts"
ADD CONSTRAINT "fk_users_carts" FOREIGN KEY (user_id) REFERENCES "users" (id);
ALTER TABLE "cart_items"
ADD CONSTRAINT "fk_carts_cart_items" FOREIGN KEY (cart_id) REFERENCES "carts" (id) ON DELETE CASCADE;
ALTER TABLE "product_images"
ADD CONSTRAINT "fk_products_product_images" FOREIGN KEY (product_id) REFERENCES "products" (id) ON DELETE CASCADE;
ALTER TABLE "cart_items"
ADD CONSTRAINT "fk_products_cart_items" FOREIGN KEY (product_id) REFERENCES "products" (id);
ALTER TABLE "order_items"
ADD CONSTRAINT "fk_vendors_order_items" FOREIGN KEY (vendor_id) REFERENCES "vendors" (id);
ALTER TABLE "products"
ADD CONSTRAINT "fk_categories_products" FOREIGN KEY (category_id) REFERENCES "categories" (id);
ALTER TABLE "payments"
ADD CONSTRAINT "fk_orders_payments" FOREIGN KEY (order_id) REFERENCES "orders" (id) ON DELETE CASCADE;Sqlite
Learn how to import existing SQLite database schemas into StackRender using tools like sqlite3 and DB Browser for SQLite. Convert your SQL schema into a visual ERD diagram in seconds.
AI Assistant
StackRender AI helps you design database schemas faster using artificial intelligence. Generate ER diagrams from text, get smart index suggestions, enrich your schema, and automatically produce clean documentation for your database.