SQL CREATE TABLE Generator
Generate a SQL CREATE TABLE statement from JSON or CSV sample data, with column types, keys and NOT NULL worked out for you.
Runs in your browser. Nothing is uploaded.
| Column | Type | What was found |
|---|
How to use the SQL CREATE TABLE Generator
- Paste sample data as a JSON array of objects or as CSV with a header row, or open a file.
- Choose your database and type a table name.
- Pick the primary key, or let the tool detect it or add a new auto-incrementing id column. Adjust the type options if you like.
- Check the detected columns in the table below, then copy or download the
CREATE TABLEstatement.
A table that fits your data
Designing a table for data you already have means looking through it to decide each column’s type,
whether it can be empty and how long text can get, then writing it in your database’s dialect. This
tool reads a sample in JSON or CSV and does that analysis for you, producing a CREATE TABLE
statement you can run straight away or refine.
What it works out
- Types: whole numbers, large numbers, exact decimals with the right precision and scale,
booleans, dates, timestamps, UUIDs, nested JSON and text. CSV values are typed too, so
9.99becomes a decimal andtruea boolean, while values with leading zeros, like postcodes02139, stay text. - NOT NULL: added to every column that is filled in on every row of the sample.
- Sizes: text columns get a VARCHAR with room to grow, or TEXT if you prefer.
- Keys: a primary key from your data, or a new identity column using each database’s own syntax:
GENERATED ALWAYS AS IDENTITYin PostgreSQL,AUTO_INCREMENTin MySQL,AUTOINCREMENTin SQLite andIDENTITY(1,1)in SQL Server. - Unique constraints: columns such as email, username, sku or code whose sample values are all
different get
UNIQUE.
Column names from CSV headers are cleaned up into safe lowercase names, so Order ID becomes
order_id. The table under the editor lists every column with its type and what was found in the
data.
Four databases
PostgreSQL, MySQL and MariaDB, SQLite and SQL Server each get their own type names and identifier
quoting. IF NOT EXISTS is written natively, or with an OBJECT_ID check for SQL Server.
Next steps
Review the result: a sample can’t tell whether a column should allow empty values in the future. To load the data itself, use CSV to SQL or JSON Converter; to see how tables relate, try the ER Diagram Generator. Everything runs privately in your browser.
Frequently asked questions
How are column types chosen?
Every value in the sample is checked. Whole numbers become INTEGER or BIGINT, numbers with decimals become DECIMAL with the precision seen, ISO dates become DATE and date-times TIMESTAMP, UUIDs get the database’s UUID type, nested objects become JSON, and everything else is text. A column takes the type that fits all its values.
How big should my sample be?
Use enough rows to show the variety in your data, including empty values and the longest texts. A column is only marked NOT NULL if no sample row leaves it empty, and VARCHAR sizes come from the longest value seen.
Why are VARCHAR sizes bigger than my longest value?
Sizes are rounded up to familiar steps (20, 50, 100, 255, 500, 1000) with at least half as much room again, so a slightly longer value next week still fits. Very long text becomes TEXT.
What does Detect do for the primary key?
It looks for a column called id, then for columns ending in _id, uuid, key or code, whose values are all filled in and all different. If none qualifies, no key is added; choose Add an id column for an auto-incrementing key.
Is my data uploaded?
No. The data is analysed in your browser and never leaves your device.
Tutorials
How to create a SQL table for a CSV file
Turn a CSV export into a CREATE TABLE statement with sensible types and keys, then import the data into PostgreSQL, MySQL or SQLite.
How to design a database table from API JSON
Generate a CREATE TABLE statement from a sample API response, with dates, UUIDs and decimals typed correctly and a primary key.