-- Enter a table name to generate SQL
What is SQL Create Table Generator?
SQL CREATE TABLE statements define the structure of database tables — column names, data types, constraints, and relationships. Writing them by hand requires memorizing syntax differences across MySQL, PostgreSQL, and SQLite, and a single typo can break your migration. This generator lets you visually design tables and produces correct, dialect-specific DDL statements instantly.
How to Use
- Enter a table name and select your target SQL dialect (MySQL, PostgreSQL, or SQLite).
- Add columns with their data types, sizes, and constraints (primary key, nullable, unique, default, auto increment).
- Optionally add foreign key relationships with ON DELETE and ON UPDATE actions.
- Configure table options (engine, charset for MySQL) and click Copy to grab the generated SQL.
Why Use This Tool?
Tips & Best Practices
- Use VARCHAR with a size for strings; TEXT has no length limit but may impact index performance in MySQL.
- In PostgreSQL, use GENERATED ALWAYS AS IDENTITY instead of SERIAL for auto-increment primary keys.
- SQLite only supports INTEGER PRIMARY KEY AUTOINCREMENT — other data types are type-affinity hints.
Frequently Asked Questions
What SQL dialects are supported?
MySQL, PostgreSQL, and SQLite. The generator maps data types and syntax to the correct form for each dialect. For example, AUTO_INCREMENT in MySQL becomes GENERATED ALWAYS AS IDENTITY in PostgreSQL and AUTOINCREMENT in SQLite.
How do I create a composite primary key?
Check the "Primary Key" checkbox on multiple columns. The generator will create a separate PRIMARY KEY constraint listing all selected columns instead of inline PRIMARY KEY on a single column.
What foreign key actions are available?
ON DELETE and ON UPDATE each support: CASCADE, SET NULL, SET DEFAULT, RESTRICT, and NO ACTION. CASCADE propagates changes; SET NULL nullifies the referencing column; RESTRICT prevents the action.
Why are table options only available for MySQL?
Engine (InnoDB/MyISAM), charset, and collation are MySQL-specific features. PostgreSQL and SQLite do not have equivalent per-table settings, so these options are hidden when those dialects are selected.
Can I use this for production migrations?
Yes — the generated SQL is standard DDL. For production, always test migrations in a staging environment first, and consider using a migration tool (Flyway, Liquibase, Prisma) to track schema versions.