Skip to content
gohacks.dev
Databases

CREATE TABLE Generator From JSON or CSV

Generate a CREATE TABLE statement from a JSON array or CSV sample, with column types inferred for MySQL, PostgreSQL or SQLite and an optional id primary key.

Free · No sign-up · Your inputs stay in your browser

Input

Generate CREATE TABLE from JSON or CSV

Output

DDL

7 columns from 2 rows

Types come from the sample: whole numbers become INT or BIGINT, decimals DECIMAL with the widest scale seen (never FLOAT, which cannot hold money exactly), ISO dates DATE or a timestamp type, objects JSON, and a column that is empty in any row is NULL. Review the lengths: a sample cannot know the longest email you will ever store.

Runs in this browser. Nothing you paste is sent to a server.

Types are a starting point

A sample shows what the data looked like, not what it may become. Review string lengths (VARCHAR sizes are rounded up to 50, 100 or 255), make columns that must always be present NOT NULL by intent rather than by accident, and add the indexes your queries need: the generator only creates the primary key.

Per database

MySQL gets an InnoDB table with utf8mb4, so emoji and all of Unicode fit; PostgreSQL gets an identity column, TIMESTAMPTZ and JSONB; SQLite gets its type affinities, since it stores any value in any column. Money is never typed as FLOAT, which cannot represent 0.1 exactly.

Share

Frequently asked questions

How do I import a CSV into MySQL after creating the table?
LOAD DATA LOCAL INFILE 'file.csv' INTO TABLE t FIELDS TERMINATED BY ',' ENCLOSED BY '"' IGNORE 1 LINES; with local_infile enabled on both client and server. In PostgreSQL, the COPY command (or psql's client-side copy meta-command) does the same.
Why is a numeric column typed as text?
One of its values is not a number, often an empty string written as a space, a thousands separator or a currency sign. Clean the column or keep it as text.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools