A laptop, a phone and a hand writing in a notebook on a wooden desk, banner image on the Database Schema Designer page

Tools / Build suite

Database Schema Designer

Describe tables in plain text. Get CREATE TABLE SQL for PostgreSQL, MySQL or SQLite, a relationship diagram and a data dictionary.

Type table names and fields such as email: string(200) required unique. The tool writes the CREATE TABLE statements for your dialect, works out foreign keys from names like customer_id or from an arrow, orders the tables so references exist when they are created, draws the relationships, and produces a Markdown data dictionary. Problems are listed with the line they came from. Everything runs in your browser. Nothing is uploaded.

Open the toolWhat is insideWhat it cannot do
Screenshot of the Database Schema Designer tool

What is inside

What is inside the tool.

Plain-text input

A line with no colon starts a table. Fields are name:type with optional words: required, unique, index, default=VALUE and an arrow ->table for a foreign key. Comments start with #.

Three dialects

PostgreSQL, MySQL and SQLite. Types, auto-increment, UUID defaults, booleans, timestamps and identifier quoting change with the dialect. Reserved words such as order and user are quoted for you, with a warning.

Foreign keys

A field named customer_id points at the customer table when it exists. An arrow, ->customer or ->customer.code, sets it directly. The column takes the type of the key it points at. A foreign key to a column that is not unique is flagged.

Order and loops

Tables are written so that referenced tables come first. If two tables refer to each other, the loop is reported and the foreign key is added with ALTER TABLE afterwards (SQLite accepts it inside CREATE TABLE).

Primary keys and options

An id primary key on every table: auto-increment integer or UUID. Optional created_at and updated_at, optional index on foreign key columns, and a delete rule: cascade, set null or restrict.

Relationship diagram

Boxes for tables, a line for each foreign key, drawn as SVG you can download. Self-references and loops are drawn.

Data dictionary

A Markdown document with every column, type, rules, default and reference, plus which tables point at each table.

Line-numbered problems

Unknown types, unreadable lines, duplicate tables or fields, bad defaults, references to tables that do not exist, and similar problems are listed with the line number. Nothing is silently dropped.

Worked example

The sample on the tool page.

Click Sample. It describes a small shop with four tables: customer, product, order and order_line.

SettingResult
PostgreSQL, integer idsIds are INTEGER GENERATED ALWAYS AS IDENTITY, TIMESTAMPTZ for timestamps, and "order" is quoted because it is a reserved word.
MySQLIds are INT AUTO_INCREMENT, timestamps are DATETIME, `order` is quoted with backticks, and no extra foreign key indexes are written because InnoDB indexes them.
SQLiteIds are INTEGER PRIMARY KEY AUTOINCREMENT. The output ran in SQLite with foreign keys switched on, and an order for a customer that does not exist was refused.
UUID idsIds become UUID with gen_random_uuid() in PostgreSQL, CHAR(36) with UUID() in MySQL, and plain TEXT in SQLite, which has no default. Foreign key columns follow.
Delete rule: cascadeEvery foreign key gets ON DELETE CASCADE. Set null on a required column triggers a warning.

Reading the result

What each part on the tool page tells you.

The summary line

Tables, columns and foreign keys it found. If a foreign key you expected is missing, the name did not match a table or the arrow was misspelled. See the list under it.

The warnings

Each says which line and what it did instead, for example "unknown type, used text". When any part differs from what you wrote, a yellow box under the SQL lists each one and says to resolve them before you run it, and the SQL starts with a comment saying so.

The diagram

A line runs from the foreign key column to the id it points at. The filled dot is at the table being pointed at.

The dictionary

Use it as documentation. Required, unique and indexed show in the Rules column.

How to use it

Five steps.

Step 1

Type or paste your tables, or click Sample and edit it.

Step 2

Pick the dialect and the primary key style.

Step 3

Read the warnings. Fix the lines they name.

Step 4

Check the SQL tab and the diagram. Switch dialects to compare.

Step 5

Copy or download the SQL, the SVG or the Markdown. Test the SQL on your database version before using real data.

Common mistakes

Things that make a schema fail or behave oddly.

A foreign key to a column that is not unique

The database rejects it. The tool does not write that foreign key. It tells you and leaves the column plain until you mark the target column unique.

Required column with delete rule set null

Deleting the parent would have to write null into a column that cannot be null. The tool writes that foreign key without a delete rule and says so.

Index or unique rule on TEXT in MySQL

MySQL needs a length to index TEXT and JSON. The rule is left out with a note. Use string(n).

Defaults that do not fit the type

default=abc on an int, or a number on a bool. They are skipped with a warning instead of producing SQL that fails.

Index names that collide

Index names are unique across a schema, and a_b with column c and a with column b_c both want idx_a_b_c. The tool numbers the second.

Reserved words as names

order, user, group and key need quoting. The tool quotes them and warns.

Names too long for the database

PostgreSQL allows 63 characters in an identifier and MySQL 64. The tool refuses to produce SQL, lists the names, and the Copy and Download buttons stay off until you shorten them.

Design notes

Facts from the PostgreSQL manual that shape the output.

Foreign keys and indexes

The PostgreSQL manual says declaring a foreign key does not automatically create an index on the referencing columns, and that it is often a good idea to index them. That is why the tool has an option to index foreign key columns, on by default. MySQL InnoDB is handled differently, so it writes none.

What a foreign key can point at

The PostgreSQL manual says a foreign key must reference a primary key or a unique constraint. The tool warns when ->table.column points at a column that is not marked unique.

Identity columns

The PostgreSQL manual describes GENERATED ... AS IDENTITY columns. The tool uses GENERATED ALWAYS AS IDENTITY for PostgreSQL integer ids.

What it cannot do

Limits.

One column keys only

Every table gets a single id primary key. There are no composite primary keys, composite unique constraints or composite foreign keys.

No many-to-many shortcut

Write the join table yourself, like order_line in the sample.

No CHECK constraints, enums or partial indexes

Add them to the SQL by hand.

Updated-at triggers

updated_at gets a default only. Refreshing it on update needs a trigger, which the tool does not write.

Not a migration tool

It writes CREATE statements for a new schema. It does not read an existing database or write ALTER scripts to change one.

Versions

The output for the sample and the edge cases was run on MySQL 8.4.3, SQLite and PostgreSQL (PGlite 0.6.1, PostgreSQL compiled to WebAssembly). Your version may differ. For example gen_random_uuid() needs PostgreSQL 13 or the pgcrypto extension, and DEFAULT (UUID()) needs MySQL 8.0.13 or later.

What it does

What Database Schema Designer does.

Free database schema designer: describe tables in plain text, get PostgreSQL, MySQL or SQLite CREATE TABLE SQL, foreign keys, indexes, an ER diagram and a data dictionary. It runs in your browser.

FunctionWhat it does
InputShort line syntax, with a type list that maps to each SQL dialect
Choose SQL dialect and primary key styleYes, PostgreSQL, MySQL, SQLite, integer or UUID

Questions

Before you ask.

Is my schema uploaded?

No. Parsing, generating and drawing run in your browser tab.

Why is a foreign key missing?

The field name must be the table name plus _id, such as customer_id, or use ->customer. The table must exist in your text.

Why is my table name in quotes?

It is a reserved word in at least one dialect, such as order, user or group. Quoting keeps the SQL valid. A different name avoids the problem.

Why does my field named id disappear?

Every table already has an id primary key, so the extra one is skipped with a warning.

Can I run the SQL as is?

Read it first and try it on a test database of your version.

What does it cost?

Nothing. No account.

Your data

What stays on your device.

The tool runs in this browser tab and does not need a server. Your table descriptions stay in the page. The .sql file, the SVG diagram and the Markdown dictionary are made on your device only when you press their buttons. Nothing is uploaded or shared.

Keep going

Other tools you may want next.

Sources

Where the facts come from.

Try it

Sketch the schema and read the SQL it makes.

Open Database Schema Designer
A laptop, headphones, a camera, a phone and a plant on a white desk, seen from above, banner image on the Database Schema Designer page

Try it now.

Database Schema Designer runs in your browser. No account needed.

Input To Output

Plain text in, schema out

Table namesand name:typelinesCREATE TABLESQLRelationshipdiagramDatadictionaryDatabase SchemaDesignerInOut
InTable names and name:type linesDatabase SchemaDesignerCREATE TABLE SQLRelationship diagramData dictionaryOut
Tables described in text become SQL, a diagram and a dictionary.

Pipeline

Writing a table

A line with nocolon starts atableEach field isname:typeAdd words afterthe typeLines starting #are comments
A line with no colon starts atableEach field is name:typeAdd words after the typeLines starting # are comments
Two kinds of line.

Before After

Reading a field line

You writeMeansemail: string(200) requireduniqueprice: decimal(10,2)requiredactive: bool default=trueText up to 200, must exist,no repeatsNumber with 2 decimals, mustexistYes or no, starts as true
You write to Meansemail: string(200) required uniqueText up to 200, must exist, norepeatsprice: decimal(10,2) requiredNumber with 2 decimals, must existactive: bool default=trueYes or no, starts as true
Each piece has a job.

Before After

Guessed foreign keys

FieldPoints atcustomer_idorder_idproduct_idwarehouse_id, no such tablecustomer.idorder.idproduct.idleft as a plain column, witha note
Field to Points atcustomer_idcustomer.idorder_idorder.idproduct_idproduct.idwarehouse_id, no such tableleft as a plain column, with a note
A field named something_id points at table something.

Bar Compare

Columns in the sample shop

customer3 columnsproduct4 columnsorder3 columnsorder_line3 columns
customer3 columnsproduct4 columnsorder3 columnsorder_line3 columns
Four tables.

Before After

PostgreSQL against MySQL

TypePostgreSQL vs MySQLtimestampjsondecimal(10,2)bool default=trueTIMESTAMPTZ vs DATETIMEJSONB vs JSONNUMERIC(10,2) vsDECIMAL(10,2)DEFAULT TRUE vs DEFAULT 1
Type to PostgreSQL vs MySQLtimestampTIMESTAMPTZ vs DATETIMEjsonJSONB vs JSONdecimal(10,2)NUMERIC(10,2) vs DECIMAL(10,2)bool default=trueDEFAULT TRUE vs DEFAULT 1
The same field, two dialects.

Support Matrix

The primary key, by dialect

Auto-incrementUUID defaultA note from thetoolPostgreSQLMySQLSQLite
PostgreSQLAuto-incrementUUID defaultA note from the toolMySQLAuto-incrementUUID defaultSQLiteAuto-incrementA note from the tool
Auto-increment integer or UUID.

Before After

The primary key line

StyleWrittenAuto-increment integerUUIDid INTEGER GENERATED ALWAYSAS IDENTITY PRIMARY KEYid UUID PRIMARY KEY DEFAULTgen_random_uuid()
Style to WrittenAuto-increment integerid INTEGER GENERATED ALWAYS ASIDENTITY PRIMARY KEYUUIDid UUID PRIMARY KEY DEFAULTgen_random_uuid()
The two styles, in PostgreSQL.

Before After

On parent delete

MenuEffectDatabase defaultCascadeSet nullRestrictNo actionChild rows go tooChild link is emptiedDelete is refused
Menu to EffectDatabase defaultNo actionCascadeChild rows go tooSet nullChild link is emptiedRestrictDelete is refused
Four choices for a foreign key.

Before After

Set null on a required field

SetupResultorder_line.order_id:requiredDelete rule: set nulla required link cannot beemptiedthe key is written without adelete rule, and a note sayswhy
Setup to Resultorder_line.order_id: requireda required link cannot be emptiedDelete rule: set nullthe key is written without a deleterule, and a note says why
The two rules clash.

Pipeline

Tables in a loop

The tables areordered so parentscome firstPostgreSQL andMySQL: looped keysgo in ALTER TABLEafterSQLite: keptinside CREATETABLE, in anyorder
The tables are ordered so parentscome firstPostgreSQL and MySQL: looped keysgo in ALTER TABLE afterSQLite: kept inside CREATE TABLE,in any order
Keys that point both ways.

Before After

Reserved words

NameIn the SQLA table named orderA column named selectquoted: CREATE TABLE "order"quoted, with a note thatanother name is easier
Name to In the SQLA table named orderquoted: CREATE TABLE "order"A column named selectquoted, with a note that anothername is easier
Names that clash with SQL.

Before After

Mistakes the parser catches

You wroteResultstring(0)decimal(50,2)rating: starsa field named idout of range; VARCHAR(255)usedprecision over 38;decimal(12,2) usedunknown type; text usedskipped; every table getsits own id
You wrote to Resultstring(0)out of range; VARCHAR(255) useddecimal(50,2)precision over 38; decimal(12,2)usedrating: starsunknown type; text useda field named idskipped; every table gets its own id
The field keeps a usable value and the note says what changed.

Before After

Name length limits

NameResultA 65-character name,PostgreSQL allows 63A 65-character name, MySQLallows 64A 60-character name, eitheroneno SQL producedno SQL producedSQL as usual
Name to ResultA 65-character name, PostgreSQLallows 63no SQL producedA 65-character name, MySQL allows 64no SQL producedA 60-character name, either oneSQL as usual
An error, not a warning: no SQL until fixed.

Input To Output

Three tabs

Your tablesSQL to copy ordownload asschema.sqlAn SVG diagramto download asschema.svgA Markdowndictionary,data-dictionary.mdTabsInOut
InYour tablesTabsSQL to copy or download asschema.sqlAn SVG diagram to download asschema.svgA Markdown dictionary,data-dictionary.mdOut
Same schema, three views.

Pipeline

The diagram, drawn

One box per table,a row per columnColumns marked pk,fk or uqA curve for eachforeign keyScrolls sidewayson narrow screens
One box per table, a row percolumnColumns marked pk, fk or uqA curve for each foreign keyScrolls sideways on narrow screens
In an SVG box.

Input To Output

The sample shop

The built-inexamplecustomer,product,order,order_line13 columns, 3foreign keysorder isquoted: it isa reservedwordSampleInOut
InThe built-in exampleSamplecustomer, product, order,order_line13 columns, 3 foreign keysorder is quoted: it is a reservedwordOut
The Sample button loads it.

Before After

Files to take away

ButtonYou getCopy SQLDownload .sqlDownload SVGDownload .mdthe schema on the clipboardschema.sqlschema.svgdata-dictionary.md
Button to You getCopy SQLthe schema on the clipboardDownload .sqlschema.sqlDownload SVGschema.svgDownload .mddata-dictionary.md
Made when you press the button.

Before After

Timestamps added

DialectResultTicked, in PostgreSQL orSQLiteTicked, in MySQLtwo columns on every table,plus a note: refreshingupdated_at needs a triggerthe tool does not writetwo columns, and no extraindex on foreign keys:InnoDB indexes them itself
Dialect to ResultTicked, in PostgreSQL or SQLitetwo columns on every table, plus a note:refreshing updated_at needs a trigger the tooldoes not writeTicked, in MySQLtwo columns, and no extra index on foreignkeys: InnoDB indexes them itself
The created_at and updated_at tick box.

Authored Tiles

The dials

3 SQL dialects10 types2 primary key styles4 delete rules
3 SQL dialects10 types2 primary key styles4 delete rules
From the code.