Documentation

ERD SQL

This page documents the SQL syntax currently supported by TinkerDiagram's ERD source editor. The source sidebar accepts SQL only, and valid SQL `CREATE TABLE` statements are reflected into the ERD canvas.

Overview

The ERD source editor is SQL-first again. The supported source contract is a practical CREATE TABLE subset aimed at schema modeling and ERD reflection, not a full SQL dialect implementation.

Valid SQL updates the ERD canvas after debounce and becomes normal diagram state for save and autosave.
Invalid or incomplete SQL stays in the editor with errors and does not replace the last valid canvas state.

Supported input model

These are the SQL constructs the ERD source editor is designed to accept and reflect into the canvas.

CREATE TABLE statements
Inline column definitions
Inline PRIMARY KEY
Inline UNIQUE
NOT NULL and NULL
DEFAULT values
Inline REFERENCES target_table(target_column)
Table-level PRIMARY KEY (...)
Table-level UNIQUE (...)
Table-level FOREIGN KEY (...) REFERENCES ...

Quick start

A minimal ERD source document is a sequence of CREATE TABLE statements.

Example document
CREATE TABLE organizations (
    id uuid PRIMARY KEY NOT NULL,
    name varchar(255) NOT NULL
);

CREATE TABLE users (
    id uuid PRIMARY KEY NOT NULL,
    organization_id uuid NOT NULL REFERENCES organizations(id),
    email varchar(255) UNIQUE NOT NULL
);

Basic table structure

Each table should be written as a standard CREATE TABLE statement with column definitions inside the body.

Basic pattern
CREATE TABLE users (
    id uuid PRIMARY KEY NOT NULL,
    email varchar(255) NOT NULL
);

Column syntax

Columns follow the standard SQL structure of name, type, and one or more supported clauses.

column_name column_type [clauses...]

Example: `created_at timestamp NOT NULL`

Column clauses

These clauses are supported directly in the SQL source editor and are reflected into the ERD model.

PRIMARY KEY

Marks a column as the primary key.

id uuid PRIMARY KEY NOT NULL
UNIQUE

Adds a unique constraint to a single column.

email varchar(255) UNIQUE NOT NULL
NOT NULL

Marks a column as required.

name varchar(255) NOT NULL
NULL

Allows null values explicitly.

middle_name varchar(255) NULL
DEFAULT

Sets a default value.

status varchar(50) DEFAULT 'draft'
REFERENCES

Declares a foreign-key relationship.

organization_id uuid NOT NULL REFERENCES organizations(id)

Table-level constraints

Composite keys and some multi-column rules belong at the table level.

Composite primary key
CREATE TABLE user_role (
    user_id uuid NOT NULL,
    role_id uuid NOT NULL,
    PRIMARY KEY (user_id, role_id)
);
Composite unique constraint
CREATE TABLE members (
    workspace_id uuid NOT NULL,
    email varchar(255) NOT NULL,
    UNIQUE (workspace_id, email)
);
Table-level foreign key
CREATE TABLE posts (
    id uuid PRIMARY KEY NOT NULL,
    author_id uuid NOT NULL,
    FOREIGN KEY (author_id) REFERENCES users(id)
);

Relationship patterns

Relationships are inferred from REFERENCES clauses and supported foreign-key constraints.

One-to-many
CREATE TABLE organizations (
    id uuid PRIMARY KEY NOT NULL,
    name varchar(255) NOT NULL
);

CREATE TABLE users (
    id uuid PRIMARY KEY NOT NULL,
    organization_id uuid NOT NULL REFERENCES organizations(id),
    email varchar(255) UNIQUE NOT NULL
);
One-to-one
CREATE TABLE users (
    id uuid PRIMARY KEY NOT NULL
);

CREATE TABLE profiles (
    id uuid PRIMARY KEY NOT NULL,
    user_id uuid UNIQUE NOT NULL REFERENCES users(id)
);
Many-to-many via join table
CREATE TABLE users (
    id uuid PRIMARY KEY NOT NULL
);

CREATE TABLE roles (
    id uuid PRIMARY KEY NOT NULL
);

CREATE TABLE user_role (
    user_id uuid NOT NULL REFERENCES users(id),
    role_id uuid NOT NULL REFERENCES roles(id),
    PRIMARY KEY (user_id, role_id)
);

Supported editor behavior

These behaviors define how SQL source editing interacts with the ERD canvas and persistence flow.

Valid SQL updates the ERD canvas after debounce.
Invalid or incomplete SQL stays local in the editor and only shows errors.
REFERENCES creates and updates ERD relationships automatically.
Saving persists the valid diagram state derived from the canvas.

Not supported yet

The source editor intentionally supports a constrained SQL subset rather than arbitrary SQL.

Arbitrary SQL statements outside the ERD subset.
Dialect-specific syntax beyond the currently supported clauses.
Standalone enum declarations in the source editor.
Index statements outside CREATE TABLE.
Check constraints in the SQL source editor.
Treating comments or migration directives as first-class ERD syntax.