-- 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. For example, AUTO_INCREMENT in MySQL becomes GENERATED ALWAYS AS IDENTITY in PostgreSQL and AUTOINCREMENT in SQLite; BOOLEAN maps to INTEGER in SQLite; and JSONB is PostgreSQL-specific. This generator lets you visually design tables and produces correct, dialect-specific DDL statements instantly, handling type mapping, constraint syntax, foreign key references, and MySQL-specific table options like engine and charset.
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 (CASCADE, SET NULL, RESTRICT, etc.).
- For MySQL, configure table options like engine (InnoDB/MyISAM), charset (utf8mb4), and collation.
- Click Copy to grab the generated SQL and paste it into your database client or migration file.
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 — SERIAL is a legacy shortcut.
- SQLite only supports INTEGER PRIMARY KEY AUTOINCREMENT — other data types are type-affinity hints, not enforced constraints.
- For composite primary keys, check the Primary Key checkbox on multiple columns — the generator creates a separate PRIMARY KEY constraint.
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. BOOLEAN maps to INTEGER in SQLite, and JSON maps to JSONB in PostgreSQL.
When should I NOT use this SQL table generator?
This generator creates basic CREATE TABLE statements. It does not support: partial indexes, CHECK constraints, generated columns, exclusion constraints, table partitioning, or database-specific features like PostgreSQL enums and arrays. For advanced schema designs, extend the generated SQL manually or use a database IDE.
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 (propagate changes), SET NULL (nullify the referencing column), SET DEFAULT, RESTRICT (prevent the action), and NO ACTION (default, similar to RESTRICT). CASCADE is the most commonly used for maintaining referential integrity.
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.
Is my table schema data sent to any server?
No. The SQL Table Generator runs entirely in your browser. No table names, column definitions, or generated SQL is sent to any server. You can safely design tables for internal databases without exposing your schema.
Real-world Examples
Users table with MySQL dialect
A standard users table with auto-increment primary key, unique email constraint, and timestamp columns — generated for MySQL with InnoDB engine and utf8mb4 charset.
Table: users (MySQL) Columns: id INT PK AUTO_INCREMENT, username VARCHAR(50) UNIQUE NOT NULL, email VARCHAR(255) UNIQUE NOT NULL, password_hash VARCHAR(255) NOT NULL, is_active BOOLEAN DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
CREATE TABLE users ( id INT NOT NULL AUTO_INCREMENT, username VARCHAR(50) NOT NULL UNIQUE, email VARCHAR(255) NOT NULL UNIQUE, password_hash VARCHAR(255) NOT NULL, is_active BOOLEAN DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Orders table with foreign key (PostgreSQL)
An orders table referencing the users table with ON DELETE CASCADE — when a user is deleted, their orders are automatically removed.
Table: orders (PostgreSQL) Columns: id INTEGER PK GENERATED ALWAYS AS IDENTITY, user_id INTEGER NOT NULL, total DECIMAL(10,2), status VARCHAR(20) DEFAULT 'pending' Foreign Key: user_id → users(id) ON DELETE CASCADE
CREATE TABLE orders ( id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY, user_id INTEGER NOT NULL, total DECIMAL(10,2), status VARCHAR(20) DEFAULT 'pending', FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE );