Developer Tools

SQL Database Schema Generator

Sketch a whole database in a few lines per table, or start from a blog, online shop or SaaS template, and get a complete schema script. Relations are inferred from *_id columns, tables are ordered so that referenced tables come first, foreign keys get indexes, updated_at is kept current with ON UPDATE or triggers, and the script can drop old tables and run in a transaction.

  • Runs in your browser
  • No sign-up
  • Free to use
Start from an example

Start each table with “table name”. Columns: name [type] [?] [unique] [= default] [-> table]. *_id columns become foreign keys automatically. Keywords: timestamps, soft deletes, index(a, b), unique(a, b).

Options

    How to use SQL Database Schema Generator

    1. Start from a template or write your own tables.
    2. Choose the database.
    3. Pick UUID keys, drops, indexes and transaction options.
    4. Run the script on an empty database.

    SQL Database Schema Generator features

    Quick notation

    “table users”, then one column per line.

    Templates

    Blog, online shop and SaaS with teams.

    Relations

    *_id columns become foreign keys automatically.

    Dependency order

    Referenced tables created first; cycles reported.

    Indexes

    Foreign key indexes where the database does not add them.

    Four databases

    PostgreSQL, MySQL, SQLite and SQL Server.

    When to use SQL Database Schema Generator

    • Starting the database of a new project.
    • Prototyping a data model during planning.
    • Creating a realistic schema for tutorials and tests.
    • Comparing how a schema looks in different databases.

    SQL Database Schema Generator FAQ

    What does the notation look like?

    Each table starts with “table name”; each following line is a column such as “email unique”, “bio text?” or “plan enum(free, pro) = free”. Keywords add timestamps, soft deletes and indexes.

    How are relations found?

    A column called author_id refers to the authors table; “author_id -> users” chooses another table. Required relations cascade on delete, optional ones are set to NULL.

    Why does the order of tables change?

    A table can only reference tables that already exist, so tables are sorted by their dependencies. Circular references are reported, because they need ALTER TABLE afterwards.

    Can I use UUIDs?

    Yes. Primary keys and foreign keys then become UUID columns with the database’s UUID type or CHAR(36).

    Is the MySQL transaction atomic?

    No: MySQL commits each CREATE TABLE immediately. In PostgreSQL, SQLite and SQL Server the whole script is atomic.

    Is anything uploaded?

    No. The schema is generated in your browser.

    A database from a sketch

    Designing a database usually starts with a list of things and their attributes: users with an e-mail and a name, posts with an author and a title, comments on posts. Turning that sketch into SQL takes much longer than writing it, because every table needs keys, types, constraints and indexes, and the tables have to be created in the right order. This generator does that translation.

    Each table is a short block of lines. Types can be written explicitly or left to naming conventions: id is the primary key, *_id a foreign key, *_at a timestamp, is_* a boolean, email and slug bounded strings, price and total decimals. Keywords add created_at and updated_at, soft deletes and composite indexes or unique constraints.

    Relations follow from the names. author_id points to authors unless written as author_id -> users; required references cascade on delete and optional ones are set to NULL. The generator then sorts the tables by their dependencies, so a CREATE TABLE never references a table that does not exist yet, and reports circular references that must be completed with ALTER TABLE.

    The script is written for the database you choose, with its own types and syntax. PostgreSQL, SQLite and SQL Server get indexes on foreign key columns, which they do not create automatically, and a trigger keeps updated_at current where MySQL would use ON UPDATE CURRENT_TIMESTAMP.

    The templates show complete, realistic schemas: a blog with categories, comments and a tag linking table; a shop with customers, addresses, products, orders and order items; and a SaaS model with teams, memberships, projects and API keys.

    Other useful tools