Skip to content

Convert

CSV to SQL

CSV to SQL

Paste a CSV and get CREATE TABLE plus INSERT statements for PostgreSQL, MySQL, or SQLite. Column types are inferred, quoted commas survive, and empty cells become NULL. Runs in your browser.

Use via API
  • Free, no sign-up
  • REST + MCP
  • Updated
  • Reviewed by Olgun Ozoktas
Dialect
CSV Input
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SQL Output

SQL statements will appear here..

Why Use Our CSV to SQL Converter?

Loading a spreadsheet into a database usually means either writing the INSERT statements by hand or uploading the file to a site you do not control. Neither is appealing when the CSV holds customer records or unreleased figures. This converter reads the CSV in your browser, infers a type for each column, and writes the SQL you can paste straight into psql, the MySQL client, or the SQLite shell. It never connects to a database and never sends the file anywhere.

CSV is how data leaves almost every system: an export button, a report download, a share from a colleague. SQL is how it gets into a database. The gap between the two is usually crossed by hand, one INSERT at a time, and that is exactly the kind of repetitive work worth removing.

This converter reads the CSV entirely in your browser. It splits the header row into a column list, samples the first fifty data rows to infer whether each column is an integer, a decimal, a boolean, or text, and then writes a CREATE TABLE followed by the INSERT statements. Quoting follows the dialect you choose, so the output runs without editing whether you paste it into PostgreSQL, MySQL, or SQLite.

Nothing is executed. The tool produces SQL text and hands it to you; connecting to a database and running it stays your decision, on your machine, with your credentials.

How it compares

Most online CSV to SQL sites upload the file to a server to do the parsing. For a public dataset that is fine. For an export of customer emails, a payroll sheet, or anything under an NDA, it means handing the file to a third party for a job a browser can do on its own. This converter never makes that request.

CSV to SQL Tips

  • Types are inferred from the first 50 data rows. A column that mixes 1 and 2.5 becomes numeric; a column with one non-numeric value becomes text.
  • An empty cell never narrows a type. A column of integers with a gap is still an integer column.
  • Identifiers are quoted for the dialect you pick: backticks for MySQL, double quotes for PostgreSQL and SQLite.
  • A value containing a single quote is escaped by doubling it, which is portable across all three databases.
  • SQLite has no boolean literal, so true and false are written as 1 and 0 for that dialect only.

Frequently Asked Questions

Does my CSV get uploaded anywhere?

No. The CSV is parsed in your browser and the SQL is generated there too. Open your browser developer tools, switch to the Network tab, and convert a file: you will see no request carrying the CSV. That makes the tool safe for exports containing customer records, financial figures, or anything else you cannot share with a third party.

How are column types decided?

Each column is sampled across the first 50 data rows. A column whose values are all whole numbers becomes an integer type; one that mixes whole numbers and decimals becomes numeric; one containing only true and false becomes boolean; anything else becomes text. Empty cells are ignored during inference, so a column of integers with a few gaps is still an integer column. If a single value does not fit, the column widens to text rather than producing SQL that fails on import.

What happens to a comma inside a quoted value?

It is preserved. The parser follows RFC 4180: a value wrapped in double quotes may contain commas, and a doubled quote inside such a value means one literal quote. A cell reading "Doe, John" becomes the single SQL literal 'Doe, John' rather than two columns.

How are empty cells handled?

By default an empty cell becomes NULL, which is almost always what you want in a database. Turn off "Empty cell becomes NULL" to write an empty string instead, which matters when a column is NOT NULL or when an empty string and a missing value mean different things in your schema.

Which SQL dialects are supported?

PostgreSQL, MySQL, and SQLite. The dialect changes two things: how identifiers are quoted, and which type names appear in the CREATE TABLE. MySQL uses backticks around names; PostgreSQL and SQLite use double quotes. Type names follow each database's conventions, and SQLite stores booleans as 1 and 0 because it has no boolean literal.

Can I skip the CREATE TABLE?

Yes. Turn off "Include CREATE TABLE" and the output is INSERT statements only, which is what you want when the table already exists and you are just loading rows into it.

What is the difference between one INSERT per row and a multi-row INSERT?

One statement per row is easier to read and easier to run partially: if one row fails, the others still land. A single multi-row INSERT is considerably faster for large imports because the database plans it once, but it is all-or-nothing inside a transaction. Use per-row for a few dozen rows and the multi-row form for thousands.

Does it handle a CSV with a semicolon or tab delimiter?

Not yet — the parser reads comma-separated values. If your export uses semicolons or tabs, run it through the CSV to JSON side of the JSON CSV Converter first, or open it in a spreadsheet and re-export with commas.

What happens to a cell containing JSON?

It is written as a quoted SQL string containing the JSON text, with its internal quotes escaped. It is never rendered as the literal text [object Object], which is a common failure in converters that stringify without checking the value type. If the target column is a JSON or JSONB column, the string literal will cast cleanly on insert.

Is there a row limit?

There is no server-side limit because there is no server. In practice the limit is your browser's memory. Tens of thousands of rows convert without trouble on a desktop machine; very large files are better handled by your database's own bulk loader, such as COPY in PostgreSQL or LOAD DATA INFILE in MySQL.

Rate This Tool

0/1000

Get Weekly Tools

Suggest a Tool