CSV to SQL Converter – Generate INSERT Statements Free

Convert CSV to SQL INSERT statements instantly. Paste your CSV, pick your dialect (MySQL, PostgreSQL, SQLite), and copy the SQL. Free, browser-only —

CSV
50 chars · 3 lines · 50 bytes
SQL

Turn your CSV data into ready-to-run SQL in seconds

Paste a CSV file (or upload one) and this tool spits out SQL INSERT statements you can run straight against any database — MySQL, PostgreSQL, SQLite, or SQL Server. No scripting, no manual column mapping, no wasted afternoon.

Quick start: Paste your CSV above → pick your target table name → copy the SQL. Your data never leaves the browser — nothing is uploaded to any server.

How to convert CSV to SQL

  1. Paste or upload your CSV — drop the file into the tool, or paste the raw text directly.
  2. Set a table name — this becomes the table referenced in every INSERT statement.
  3. Choose your SQL dialect — MySQL, PostgreSQL, SQLite, and SQL Server all have slight differences in quoting and data types. Pick the one that matches your database.
  4. Copy or download — click Copy to grab the SQL, or download it as a .sql file ready to import.

Worked example: CSV input → SQL output

Say you export a contacts list from a spreadsheet and get this CSV:

id,name,email,age
1,Alice,[email protected],29
2,Bob,[email protected],34
3,Carol,[email protected],41

The tool reads the header row, auto-detects that id and age are integers (not strings), and produces:

CREATE TABLE contacts (
  id INT,
  name VARCHAR(255),
  email VARCHAR(255),
  age INT
);

INSERT INTO contacts (id, name, email, age) VALUES (1, 'Alice', '[email protected]', 29);
INSERT INTO contacts (id, name, email, age) VALUES (2, 'Bob', '[email protected]', 34);
INSERT INTO contacts (id, name, email, age) VALUES (3, 'Carol', '[email protected]', 41);

String columns get single-quoted; numeric columns stay unquoted. Quoted CSV fields (values that contain commas or newlines wrapped in ") are handled correctly — the parser strips the wrapping quotes before writing the SQL value.

How to do this in Python (without the tool)

If you prefer to script the conversion, Python's csv module makes it straightforward:

import csv

table = 'contacts'

with open('contacts.csv', newline='') as f:
    reader = csv.DictReader(f)
    for row in reader:
        cols = ', '.join(row.keys())
        vals = ', '.join(
            v if v.lstrip('-').isdigit() else f"'{v}'"
            for v in row.values()
        )
        print(f'INSERT INTO {table} ({cols}) VALUES ({vals});')

This is good for automation pipelines but adds zero type-detection beyond the isdigit check. The online tool does more inference (floats, dates, booleans) without any code on your end.

How to do this in JavaScript (Node.js)

const fs = require('fs');
const lines = fs.readFileSync('contacts.csv', 'utf8').trim().split('\n');
const [headerLine, ...dataLines] = lines;
const cols = headerLine.split(',');

dataLines.forEach(line => {
  const vals = line.split(',').map(v =>
    isNaN(v) ? `'${v}'` : v
  );
  console.log(`INSERT INTO contacts (${cols.join(', ')}) VALUES (${vals.join(', ')});`);
});

Works fine for simple CSVs. For quoted fields that contain commas (e.g. "Smith, John"), you'll need a proper CSV parser like PapaParse.

How the converter works

The tool runs entirely in your browser. When you paste CSV, a client-side parser splits the data on commas and line breaks while respecting quoted fields and escaped characters. It then inspects every value column-by-column to decide the SQL data type: INT, FLOAT, DATE, BOOLEAN, or VARCHAR. Finally it renders the CREATE TABLE and INSERT INTO statements using the dialect rules you chose. Nothing leaves your machine.

When to use this tool — and when not to

Good fit Look elsewhere
One-off data imports into MySQL, PostgreSQL, SQLite, or SQL Server Millions of rows — use a LOAD DATA INFILE or COPY command directly in your database for speed
Seeding a dev or test database from a spreadsheet export Sensitive production credentials in the CSV — even though nothing is uploaded, keep PII off shared machines
Quickly turning a Google Sheets download into database seed data Complex relational imports across multiple tables — those need a migration tool like Flyway
Checking what schema a CSV would map to before writing migrations CSVs with complex nested data — consider converting to JSON first (see our JSON Beautifier for the next step)

Tips for cleaner SQL output

  • Use a clean header row — column names become SQL identifiers, so avoid spaces. first_name is safer than first name.
  • Consistent date formats help the type detector. 2024-01-15 (ISO 8601) is recognised reliably; 15/01/24 may be treated as a string.
  • Empty cells become NULL in the output — check that your table schema allows nulls in those columns.
  • If your CSV came from Excel, watch for BOM characters (\uFEFF) at the start of the file — paste into a text editor first to strip them if the first column name looks garbled.

Working with the output in other formats

Sometimes SQL isn't the final destination. If you need to clean or inspect the intermediate data as JSON first, our JSON Validator and JSON Viewer can help you catch structure problems before import. For YAML-based config files that reference the same data, try the JSON to YAML Converter.

Bottom line: paste your CSV, grab the SQL, and load your data — no installs, no sign-up, and nothing uploaded. Give the tool above a try.

Frequently asked questions

Is my CSV data uploaded to a server?+
No. The entire conversion runs in your browser using JavaScript. Your CSV file and the resulting SQL stay on your machine — nothing is sent to any server. It's safe to use with internal or sensitive data.
Which SQL dialects does the converter support?+
The tool supports MySQL, PostgreSQL, SQLite, and SQL Server (T-SQL). Each dialect has small differences in how it quotes identifiers and names data types, so pick the one that matches your database before copying the output.
What happens to CSV fields that contain commas or line breaks?+
Quoted CSV fields — where a value is wrapped in double-quotes, like "Smith, John" — are parsed correctly. The parser strips the enclosing quotes and keeps the comma as part of the value, so your SQL output won't be corrupted.
How does the tool decide the SQL data type for each column?+
It scans every value in a column and promotes the type upward: if all values look like integers it uses INT; if any have a decimal point it uses FLOAT; if any look like dates (YYYY-MM-DD) it uses DATE; everything else becomes VARCHAR(255). You can always tweak the generated CREATE TABLE statement before running it.
Can it handle large CSV files?+
It works comfortably for files up to a few thousand rows in the browser. For very large exports (100,000+ rows) you'll get better performance with a database-native import command like MySQL's LOAD DATA INFILE, PostgreSQL's \COPY, or SQLite's .import CLI command.
Is this tool free? Do I need to sign up?+
Completely free, no account needed. Paste your CSV and copy the SQL — that's it.
How do I import CSV into MySQL without converting it first?+
MySQL has a built-in LOAD DATA INFILE command that reads a CSV directly: LOAD DATA INFILE '/path/to/file.csv' INTO TABLE my_table FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS; This is faster for large files but requires direct database access. The online converter is quicker when you just need a handful of INSERT statements.
What's the difference between INSERT statements and a bulk import?+
INSERT statements add one row at a time and are easy to read, edit, and run in any SQL client. A bulk import (LOAD DATA, COPY, or bcp) streams the whole file directly into the database engine — much faster for large data sets, but less portable. For seed data or small imports, INSERTs are perfectly fine.