SQL Table Generator
Turn CSV data into SQL: a CREATE TABLE statement with detected column types and INSERT statements, for MySQL, PostgreSQL or SQLite.
Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.
How to use the SQL Table Generator
- 1 Paste the CSV or open the file.
- 2 Enter the table name and choose the database.
- 3 Copy or download the SQL and run it in your database.
About the SQL Table Generator
The generator reads a CSV file and writes the SQL to load it into a database: a CREATE TABLE statement and INSERT statements for every row. Column types are detected from the values: whole numbers become INT or BIGINT, decimals DECIMAL with the right precision, true/false BOOLEAN, YYYY-MM-DD dates DATE, and text VARCHAR(50/100/255) or TEXT.
Column and table names are made safe: lower case, letters, digits and underscores, and quoted in the style of the database (backticks for MySQL, double quotes for PostgreSQL and SQLite). Empty values become NULL, columns without empty values get NOT NULL, and quotes in text are escaped.
Rows are inserted in batches of 100 per INSERT statement, which is much faster than one statement per row and stays below the size limits of most databases. Check the types before running the SQL on important data; you can always adjust them.
Frequently asked questions
Which databases are supported?
MySQL and MariaDB, PostgreSQL and SQLite. The types and quoting differ per database.
How are column types chosen?
From all values in the column: if every non-empty value is a whole number the column becomes an integer type, and so on. One text value makes the whole column text.
What happens to empty values?
They are inserted as NULL. Columns without any empty value are declared NOT NULL.
Can I only get the INSERT statements?
Yes, turn off "CREATE TABLE" to get only the INSERTs, for example to add rows to an existing table.