LangStop · SQLite · ERD Generator

SQLite ERD Generator — Visualize SQLite Schemas

Import SQL with the SQLite option to turn the CREATE TABLE statements of a SQLite schema into an entity-relationship diagram. Paste the text from .schema in the sqlite3 shell, or a migration file, and the tables, keys and foreign keys appear on the canvas.

SQLite is the one option that does not go through @dbml/core. The code comment in this app says that @dbml/core has no SQLite importer, so the app uses its own converter, and that converter runs in your browser without a network request.

How this tool handles it

The converter is a text parser. It works in this order:

  1. It removes -- line comments and /* */ block comments.
  2. It splits the script at every ;.
  3. It keeps each statement that starts with CREATE TABLE, with or without IF NOT EXISTS. Everything else is skipped.
  4. It reads each column's name, type and constraints as written in the source.

What comes out:

  • Types are copied as written, such as INTEGER, TEXT, REAL, DATETIME or VARCHAR(255). A column without a type becomes varchar.
  • PRIMARY KEY becomes pk. AUTOINCREMENT adds increment, and a plain INTEGER PRIMARY KEY does not.
  • NOT NULL, UNIQUE and DEFAULT become settings. A literal default keeps its quotes, and an expression such as CURRENT_TIMESTAMP is wrapped in backticks.
  • CHECK is written as a // CHECK: comment, so the diagram shows it but does not enforce it.
  • Foreign keys from REFERENCES or FOREIGN KEY (...) REFERENCES become Ref lines, with delete: and update: when stated.
  • Composite keys and table UNIQUE constraints go into an indexes block.
  • STRICT at the end of a table is removed.

Worked example

CREATE TABLE customers (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  email TEXT NOT NULL UNIQUE,
  plan TEXT NOT NULL DEFAULT 'free' CHECK (plan IN ('free','pro'))
);
CREATE TABLE orders (
  id INTEGER PRIMARY KEY,
  customer_id INTEGER NOT NULL REFERENCES customers(id) ON DELETE CASCADE,
  total REAL NOT NULL,
  created DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX orders_customer ON orders(customer_id);

The DBML that comes out:

Table customers {
  id INTEGER [pk, increment]
  email TEXT [not null, unique]
  plan TEXT [not null, default: 'free'] // CHECK: plan IN ('free','pro')
}
 
Table orders {
  id INTEGER [pk]
  customer_id INTEGER [not null]
  total REAL [not null]
  created DATETIME [default: `CURRENT_TIMESTAMP`]
}
 
Ref: orders.customer_id > customers.id [delete: cascade]

The CREATE INDEX line is not in the output, and customers.id gets increment only because of AUTOINCREMENT.

Gotchas

1. A semicolon inside a string breaks the table. The split at ; does not know about quotes. Input:

CREATE TABLE notes (
  id INTEGER PRIMARY KEY,
  body TEXT DEFAULT 'a; b'
);

If the script has only that table, the import reports No CREATE TABLE statements found. If the script has other tables too, the table with the semicolon is dropped without an error. Input with a second table, pairs, that references notes:

CREATE TABLE notes (
  id INTEGER PRIMARY KEY,
  body TEXT DEFAULT 'a; b'
);
CREATE TABLE pairs (
  a INTEGER NOT NULL,
  b INTEGER NOT NULL,
  PRIMARY KEY (a, b),
  FOREIGN KEY (a) REFERENCES notes(id) ON DELETE CASCADE
);

The DBML that comes out has pairs and a Ref to notes, but no notes table:

Table pairs {
  a INTEGER [not null]
  b INTEGER [not null]
  indexes {
    (a, b) [pk]
  }
}
 
Ref: pairs.a > notes.id [delete: cascade]

The DBML parser rejects that output with a Can't find table error for notes. Replace the semicolon in the string, or remove the default, before you import.

2. Generated columns lose their expression. Input total REAL GENERATED ALWAYS AS (id * 2) STORED becomes total REAL. The column stays, but the diagram does not show that it is computed.

3. Indexes are not drawn. Standalone CREATE INDEX statements are skipped. In the example above, orders_customer is not in the output. Only the REFERENCES clause on customer_id appears, as a Ref.

4. CHECK is a comment, not a rule. CHECK (plan IN ('free','pro')) is written as // CHECK: plan IN ('free','pro'). The DBML is valid, and the diagram shows the rule in a comment only.

5. Views and triggers are not drawn. A CREATE VIEW or CREATE TRIGGER statement is skipped, the same way as CREATE INDEX.

Frequently asked questions

How do I get the schema as SQL text?

Run .schema in the sqlite3 shell. It prints the CREATE statements of the database, and you paste that text into Import SQL with the SQLite option.

Can I load a .sqlite database file directly?

No. The file picker reads the chosen file as text, so a binary database file does not parse. Export the schema as SQL text first.

Are foreign keys imported?

Yes, from both column-level REFERENCES and table-level FOREIGN KEY clauses, including ON DELETE and ON UPDATE actions. Each one becomes a Ref line.

Why is one of my tables missing from the diagram?

The converter splits the script at every semicolon, including semicolons inside a quoted default. A table that contains one is cut in two and is dropped. If it was the only table, the import reports that no CREATE TABLE statements were found. Remove the semicolon from the string, or edit the default in the text before you import.