SQL Table Generator
FV-38Describe a table with one line per column and get a CREATE TABLE statement for MySQL, PostgreSQL, SQL Server, SQLite or Oracle, with keys, defaults and foreign keys.
Runs in your browser. Nothing is uploaded.
Table name, then one column per line: name type [pk] [ai] [nn] [unique] [index] [default x] [ref t(c)]
SQL
How to use it
- Write the table name on the first line.
- Add one column per line: name, type, then pk, ai, nn, unique, index, default or ref words.
- Choose the database, and whether names are quoted.
- Click Generate CREATE TABLE and run the result in your database client.
Column line format
A column line is name, type and any of: pk (primary key), ai (auto-increment), nn (not null), null, unique, index (adds a CREATE INDEX), default VALUE, and ref table(column) for a foreign key. The simple types int, bigint, smallint, string, text, bool, date, datetime, float, double, decimal, uuid and json are translated for each database; any other type, such as varchar(100) or char(2), is copied as typed. Several pk columns give one composite primary key.
Per database behaviour
Auto-increment becomes AUTO_INCREMENT in MySQL, SERIAL or an identity column in PostgreSQL, IDENTITY(1,1) in SQL Server and an identity column in Oracle; SQLite allows it only on a single integer primary key. Foreign keys are written as table constraints because MySQL ignores them inside a column definition. true and false defaults become 1 and 0 where no boolean type exists. Other default expressions are copied as typed. The statement is not run, so check it against your database version.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Line 2: "1id" is not a valid column name. Use letters, digits and underscores, not starting with a digit. | A column name starts with a digit or contains other characters. | Rename the column, for example id1. |
Add at least one column under the table name, one per line, such as: email string nn unique | Only a table name was given. | Add column lines under the name. |
Questions people ask
How do I generate a CREATE TABLE statement?
Type the table name, then one column per line, and click Generate CREATE TABLE. Pick the database first so types and auto-increment match. Tick the if-not-exists option when you want the statement to be safe to run twice.
How do I make an auto-increment primary key?
Write id int pk ai. The tool writes AUTO_INCREMENT, SERIAL, IDENTITY or AUTOINCREMENT, whichever your chosen database uses, together with the primary key. SQLite needs the key to be a single integer column.
How do I add a foreign key?
Add ref other_table(column) to the column line, for example team_id int ref teams(id). The tool writes a FOREIGN KEY constraint at the end of the table definition.
What does Only if the table does not exist do?
It writes CREATE TABLE IF NOT EXISTS for MySQL, PostgreSQL and SQLite, and an OBJECT_ID check for SQL Server. For Oracle no clause is written, because Oracle before 23ai does not support it, and a comment at the top says so.
Why do some types look different between databases?
The simple names such as string or datetime are mapped to each database's nearest type, for example VARCHAR(255) or NVARCHAR(255). Types you write yourself are used as typed.
Can it create indexes?
Yes. Add the word index to a column and a separate CREATE INDEX statement is written after the table, named idx_ followed by the table and column names.
About this tool
The first line is the table name. Each column line is: name, type, then any of pk, ai (auto-increment), nn (not null), null, unique, index, default VALUE and ref table(column). The plain type names int, bigint, smallint, string, text, bool, date, datetime, float, double, decimal, uuid and json are translated for the chosen database; anything else, such as varchar(100), is written as typed in capitals. Several pk columns become one composite key. Foreign keys are written as table constraints, because MySQL ignores them inside a column definition. SQLite allows auto-increment only on a single integer primary key. true and false defaults become 1 and 0 where there is no boolean type. Other default expressions are copied as typed, not translated. Oracle has no IF NOT EXISTS here. The statement is not run.