Export to SQL (DDL)

Design your schema on the canvas, then export it as a ready-to-run .sql file in your diagram's dialect — MySQL, PostgreSQL, or SQL Server. Run it against an empty database and your schema exists for real.

Exporting

  1. In the diagram editor, click FileExport.

  2. Pick the SQL export matching your diagram's DBMS (MySQL, PostgreSQL, or SQL Server).

  3. Click Start export — the .sql file downloads automatically.

Have tables selected on the canvas? The export scopes to your selection, so you can hand a teammate just one domain of a big schema.

The file contains a CREATE TABLE per table — columns, primary keys, indexes, and comments included — with foreign keys added as ALTER TABLE statements at the end, so tables can be created in any order.

Running the export

 # MySQL / MariaDB
mysql -u USERNAME -p DATABASE < export.sql

# PostgreSQL
psql -d DATABASE -f export.sql

# SQL Server
sqlcmd -S SERVER -d DATABASE -i export.sql

Sample export output

 CREATE TABLE `regions`(
    `region_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `region_name` VARCHAR(25) NULL
);
CREATE TABLE `countries`(
    `country_id` CHAR(2) NOT NULL,
    `country_name` VARCHAR(40) NULL,
    `region_id` INT NOT NULL
);
ALTER TABLE
    `countries` ADD PRIMARY KEY(`country_id`);
CREATE TABLE `departments`(
    `department_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `department_name` VARCHAR(30) NOT NULL,
    `location_id` INT NULL
);
ALTER TABLE
    `countries` ADD CONSTRAINT `countries_region_id_foreign` FOREIGN KEY(`region_id`) REFERENCES `regions`(`region_id`);

Still have a question? We'd love to help!