CSV to SQL INSERT Generator
Paste a CSV export and get a ready-to-run SQL script: a CREATE TABLE statement with inferred column types, followed by batched INSERT INTO statements. Nothing is uploaded — every line of SQL is generated in your browser. Need JSON instead of SQL? Use the CSV to JSON converter, and tidy any JSON you paste back with the JSON formatter.
What it does
This generator turns tabular text into SQL you can run directly against a database. It reads a CSV block from the text area, splits it into rows and fields with an RFC 4180 style parser, works out a sensible type for every column, and prints two things: a CREATE TABLE statement that describes the table, and a set of INSERT INTO ... VALUES statements that fill it. The whole script is assembled as plain text, so you can copy it, save it, or review it line by line before anything touches a real database.
The parser is deliberately forgiving where CSV files are messy in practice and strict where mistakes would silently corrupt data. Quoted fields may contain the delimiter, line breaks inside quoted fields survive intact, and an escaped quote written as two double quotes becomes a single quote in the value. A byte order mark at the start of the file is ignored. If a data row has a different number of columns than the header, the tool stops and tells you which row is wrong rather than shifting every value by one — that failure mode is common in hand-edited spreadsheets and it is worth catching early.
Everything is local. There is no upload step, no account and no server-side call: the JavaScript that runs the conversion is the same file that rendered this page. That matters when the CSV holds customer records, exports from an internal tool, or anything you would rather not paste into a third-party service. The output is plain SQL text, so you stay in control of how it is stored and run.
How to use it
Paste your data, choose the options, then copy the result. In detail:
- Paste the CSV into the data box. The first line is usually your header row; rows are separated by newlines.
- Pick the delimiter that matches the file. Comma is the default, but exports from European locales often use a semicolon and some tools use a tab or a pipe.
- Set the header checkbox so the first row becomes the column names. If you leave it unchecked, the columns are named column_1, column_2 and so on.
- Name the table. A short, lowercase name such as
customerskeeps the identifiers readable across engines. - Choose the dialect — MySQL, PostgreSQL or SQLite — so identifiers are quoted the way that engine expects.
- Set the batch size, which is how many rows go into each INSERT statement. A batch of one gives one INSERT per row; larger batches produce multi-row VALUES lists.
- Press Generate SQL and the script appears in the output box, ready to copy into your database client.
The logic is written for CSV, so it makes no attempt to guess at a schema you have not described. If you already have a table, simply ignore the CREATE TABLE statement and use the INSERT statements; they name their columns explicitly, so the order of the CSV columns does not have to match the order in the table.
Options
- Delimiter — comma, semicolon, tab or pipe. Choose the character that actually separates your fields, otherwise a whole line is read as a single column.
- First row is a header — when ticked, the first row supplies column names and is not inserted as data.
- Table name — used in the CREATE TABLE and every INSERT. Blank names fall back to
data. - Dialect — controls identifier quoting and nothing else; the statement shape is standard SQL. Backticks for MySQL, double quotes for PostgreSQL and SQLite.
- Rows per INSERT — the batch size. Bigger batches mean fewer round trips and faster loading, up to the statement size limit of your server.
Type inference, NULLs and escaping
Types are inferred per column rather than per cell, because a SQL column has one type. A column whose values are all whole numbers becomes INTEGER; a column containing at least one decimal or exponent becomes REAL; and a column with any non-numeric value becomes TEXT. Text columns keep numeric-looking values as quoted strings so no leading zero is lost, which is the correct choice for identifiers such as postal codes and phone numbers. Empty cells are written as NULL, the honest representation of a missing value, rather than as an empty string that could be confused with deliberately empty text.
String values are wrapped in single quotes and any single quote inside them is doubled, so names such as O'Brien and apostrophes inside addresses cannot break the statement. Integer and REAL values are emitted without quotes so the database parses them as numbers. Nothing is interpolated from the page into a shell command, and the generator never executes the SQL it produces.
Frequently asked questions
Does this tool send my CSV anywhere?
No. The parser and the SQL writer run entirely in your browser with plain JavaScript, so the pasted data never leaves your device and nothing is stored between visits.
Which SQL dialects are supported?
MySQL, PostgreSQL and SQLite. Table and column names are quoted with backticks for MySQL and with double quotes for PostgreSQL and SQLite, which is the identifier syntax each engine accepts.
How are column types decided?
Every column is scanned and typed as INTEGER, REAL or TEXT. A column is INTEGER when all of its values are whole numbers, REAL when at least one value carries a decimal point or exponent, and TEXT as soon as a single value is not numeric.
How are quotes and empty cells handled?
A single quote inside a value is doubled, which is the standard SQL escape, so O'Brien is written as 'O''Brien'. Empty cells are emitted as NULL rather than as an empty string.
What does the batch size control?
It sets how many rows share one INSERT statement. A batch of one emits an INSERT per row, while larger batches produce multi-row VALUES lists that load faster on most engines.
Can I use the first row as column names?
Yes. Tick the header checkbox and the first row supplies the column names; otherwise the columns are named column_1, column_2 and so on in order.
Does it generate a CREATE TABLE statement?
Yes. The output starts with a CREATE TABLE statement that lists each column with its inferred type, followed by the INSERT statements, so the script can run against an empty database.
Is the output suitable for large files?
The tool works on the text you paste and builds the whole script in memory, so it is comfortable with the tens of thousands of rows a browser can hold. For very large exports, use a database command line loader instead.
Related: convert the same data to JSON with the CSV to JSON tool, go the other way with JSON to CSV, produce XML with JSON to XML, or beautify a payload first in the JSON formatter. Browse every browser-only utility on the all tools page.
Technical note: the parser follows the RFC 4180 common subset (quoted fields, doubled quotes, embedded newlines, optional byte order mark) and the generator emits standard SQL for MySQL, PostgreSQL and SQLite. The tool is dependency-free vanilla JavaScript and runs entirely in your browser — no CSV content, table names or generated SQL are sent anywhere. Search-demand figures quoted anywhere on this page are estimates, not measured guarantees, and are given only as background to how common the CSV-to-database task is.