Skip to content

SQL Export

Export the entity structure from your ERD as a DDL (Data Definition Language) script for application to an actual database.


Export Method

Go to Menu > File > Export as SQL.

SQL Export Dialog Screen showing target DBMS selection, DDL preview, and export options

Supported DBMS

ThinkERD automatically converts your logical model to the appropriate physical syntax for each DBMS.

DBMS String Numeric Large Text Date
Oracle VARCHAR2 NUMBER CLOB DATE
PostgreSQL VARCHAR NUMERIC TEXT DATE
MySQL VARCHAR INT / DECIMAL LONGTEXT DATE
SQL Server NVARCHAR DECIMAL NVARCHAR(MAX) DATE

Domain Integration

If standard domains are configured, the domain's DBMS-specific type slots are automatically applied. The same Amount domain converts to NUMBER(18,2) in Oracle and NUMERIC(18,2) in PostgreSQL.


Generated DDL Elements

ERD Element DDL Description
Entity CREATE TABLE Table creation
PK Column PRIMARY KEY constraint Unique identifier
FK (Relationship) FOREIGN KEY ... REFERENCES Foreign key reference
NOT NULL NOT NULL constraint Required column
UNIQUE UNIQUE constraint Uniqueness constraint
Default Value DEFAULT clause Default value setting

DDL Output Examples

-- Customer Table
CREATE TABLE CUSTOMER (
    CUST_NO   VARCHAR2(20) NOT NULL,
    CUST_NM   VARCHAR2(100),
    EMAIL     VARCHAR2(200),
    REG_DT    DATE DEFAULT SYSDATE,
    CONSTRAINT PK_CUSTOMER PRIMARY KEY (CUST_NO)
);

-- Order Table
CREATE TABLE ORD (
    ORD_NO    VARCHAR2(20) NOT NULL,
    CUST_NO   VARCHAR2(20) NOT NULL,
    ORD_DT    DATE,
    ORD_AMT   NUMBER(18,2),
    CONSTRAINT PK_ORD PRIMARY KEY (ORD_NO),
    CONSTRAINT FK_ORD_CUST
      FOREIGN KEY (CUST_NO) REFERENCES CUSTOMER (CUST_NO)
);
CREATE TABLE customer (
    cust_no   VARCHAR(20) NOT NULL,
    cust_nm   VARCHAR(100),
    email     VARCHAR(200),
    reg_dt    DATE DEFAULT CURRENT_DATE,
    CONSTRAINT pk_customer PRIMARY KEY (cust_no)
);

CREATE TABLE ord (
    ord_no    VARCHAR(20) NOT NULL,
    cust_no   VARCHAR(20) NOT NULL,
    ord_dt    DATE,
    ord_amt   NUMERIC(18,2),
    CONSTRAINT pk_ord PRIMARY KEY (ord_no),
    CONSTRAINT fk_ord_cust
      FOREIGN KEY (cust_no) REFERENCES customer (cust_no)
);
CREATE TABLE CUSTOMER (
    CUST_NO   VARCHAR(20) NOT NULL,
    CUST_NM   VARCHAR(100),
    EMAIL     VARCHAR(200),
    REG_DT    DATE DEFAULT (CURRENT_DATE),
    PRIMARY KEY (CUST_NO)
) ENGINE=InnoDB;

CREATE TABLE ORD (
    ORD_NO    VARCHAR(20) NOT NULL,
    CUST_NO   VARCHAR(20) NOT NULL,
    ORD_DT    DATE,
    ORD_AMT   DECIMAL(18,2),
    PRIMARY KEY (ORD_NO),
    CONSTRAINT FK_ORD_CUST
      FOREIGN KEY (CUST_NO) REFERENCES CUSTOMER (CUST_NO)
) ENGINE=InnoDB;

Alter Script (Change Script)

Compare two versions of a diagram to auto-generate ALTER statements.

Change Type ALTER Statement
Column added ALTER TABLE ... ADD COLUMN ...
Column type changed ALTER TABLE ... ALTER COLUMN ... TYPE ...
Column dropped ALTER TABLE ... DROP COLUMN ...
Table dropped DROP TABLE ...
Relationship added ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY ...

→ For version comparison, see Version Diff.


Usage Workflows

Development DB Initialization

  1. Design the full entity structure in the ERD
  2. Extract DDL for the target DBMS using Export as SQL
  3. Execute the extracted DDL on the development DB to create tables

Schema Change Deployment

  1. Reflect changes in the ERD (add columns, change types, etc.)
  2. Verify changes using Version Diff
  3. Generate an Alter Script to extract the change script
  4. Apply to staging/production DB

Review before production deployment

Always test auto-generated DDL in a development/staging environment before applying to production. Column deletions and type changes in particular can cause data loss.