Developer Tools

MySQL Table Generator

Build a MySQL table without remembering the syntax. Add a row per column, pick the type, size, key and default, and get a complete CREATE TABLE statement with InnoDB, utf8mb4, foreign keys, indexes and timestamps that MySQL keeps up to date with ON UPDATE CURRENT_TIMESTAMP. Notes explain MySQL specifics and point out design problems such as money stored as FLOAT or foreign keys without indexes.

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

    How to use MySQL Table Generator

    1. Enter the table name and add a row per column.
    2. Choose types, sizes, keys, defaults and references.
    3. Pick timestamps, soft delete, engine and collation.
    4. Copy or download the CREATE TABLE statement.

    MySQL Table Generator features

    Visual columns

    Name, type, size, default, primary key, auto increment, NOT NULL, unique.

    MySQL types

    BIGINT, DECIMAL, TINYINT(1) for booleans, ENUM, JSON, DATETIME.

    Relations

    Foreign keys with ON DELETE CASCADE, SET NULL or RESTRICT.

    Timestamps

    created_at and updated_at with ON UPDATE CURRENT_TIMESTAMP.

    Table options

    InnoDB, utf8mb4 and the right collation for MySQL 8 or MariaDB.

    Design advice

    Missing primary keys, FLOAT money and oversized VARCHARs.

    When to use MySQL Table Generator

    • Designing tables for a PHP, Laravel or WordPress project.
    • Creating a table in phpMyAdmin or MySQL Workbench quickly.
    • Learning MySQL column types and constraints.
    • Documenting a table design for a team.

    MySQL Table Generator FAQ

    Which collation should I choose?

    utf8mb4_0900_ai_ci is the MySQL 8 default and sorts according to modern Unicode rules. MariaDB and MySQL 5.7 do not have it; use utf8mb4_unicode_ci there.

    Why BIGINT for ids?

    INT stops at about 2.1 billion (4.2 billion unsigned). BIGINT costs four more bytes per row and never runs out in practice.

    How are booleans stored?

    MySQL has no real boolean type; BOOLEAN is an alias for TINYINT(1), storing 1 and 0.

    What does ON UPDATE CURRENT_TIMESTAMP do?

    MySQL sets updated_at to the current time whenever the row changes, without any application code.

    Why does a foreign key need the same type?

    MySQL requires the referencing and referenced columns to have the same integer type and signedness; otherwise CREATE TABLE fails with error 3780.

    Is anything uploaded?

    No. The SQL is generated in your browser.

    Designing MySQL tables

    A good table definition is the foundation of an application: types that fit the data, keys that make rows identifiable, constraints that keep data consistent and indexes that make queries fast. The generator turns a list of columns into a complete MySQL statement and applies the defaults that experienced MySQL developers use.

    Each column row has the essentials: name, type, size, default, and flags for primary key, auto increment, NOT NULL and unique. Size means the length for VARCHAR and CHAR, precision and scale for DECIMAL (10,2 for money) and the list of values for ENUM. Defaults accept numbers, text, true and false, NULL and now, which becomes CURRENT_TIMESTAMP.

    Relations are entered as table.column in the reference field and become named FOREIGN KEY constraints with the ON DELETE behaviour you choose: RESTRICT to prevent deleting a parent that still has children, CASCADE to delete them too, or SET NULL to keep them without a link. InnoDB creates an index for each foreign key automatically.

    Table options follow current MySQL practice: the InnoDB engine for transactions and crash safety, the utf8mb4 character set so every Unicode character including emoji fits, and a collation matching your server. Timestamps add created_at and updated_at, the latter maintained by ON UPDATE CURRENT_TIMESTAMP; soft delete adds an indexed deleted_at column.

    The advice under the SQL catches common mistakes: a table without a primary key, prices stored as FLOAT or DOUBLE, which cannot represent amounts such as 0.10 exactly, and VARCHAR columns so long that TEXT would be the better choice.

    Other useful tools