About the SQL Table Generator
Type a column per line as name type flags. The flags are short words: pk for the primary key, auto for a generated identifier, notnull, unique, index, default:VALUE and ref:other_table.id for a foreign key. Blank lines and anything after a # are ignored, so you can annotate the sketch while you work.
Types are translated for the dialect you choose. An auto increment key becomes INT AUTO_INCREMENT PRIMARY KEY in MySQL, GENERATED ALWAYS AS IDENTITY in PostgreSQL, INTEGER PRIMARY KEY AUTOINCREMENT in SQLite and IDENTITY(1,1) in SQL Server. A bool becomes BOOLEAN, TINYINT(1), INTEGER or BIT, and its default is rewritten to TRUE or 1 to match. Unsized varchar is given a length rather than left invalid.
Anything the generator does not recognise is passed through in upper case, so a native type such as inet or geography still lands in the statement untouched. Foreign keys become named table constraints, and every column flagged index gets its own CREATE INDEX after the table, named from the table and column so two tables never collide.
The optional timestamp pair adds created_at and updated_at with the right default expression for the dialect. Once the table exists, generate statements against it with the SQL Query Generator, or load rows from a file using CSV to SQL.
How to use
- Write one column per line as
name type flags, or press Sample for a worked example. - Name the table and pick your database dialect.
- Tick Add created_at and updated_at if you want the usual audit columns.
- Copy the statement or download
schema.sqlfor your migration.
Common questions
- Which flags does a column line accept?
- pk, auto, notnull, unique, index, default:VALUE and ref:table.column. Order does not matter and unknown words are ignored.
- How do I make a composite primary key?
- Put pk on each column of the key without auto. They are collected into a single PRIMARY KEY constraint at the end of the statement.
- Can I use a type the tool does not know?
- Yes. An unrecognised type is passed straight through in upper case, so native types such as inet or jsonb still work.
- Why is IF NOT EXISTS missing on SQL Server?
- SQL Server has no such clause on CREATE TABLE. The option is skipped for that dialect so the statement stays valid.