Skip to content

Free · Reliable output · No signup

Convert CSV to SQL

Generate SQL INSERT, UPDATE, DELETE or native upsert with explicit keys and column types. Preview, copy and download for free.

Add as many files as you need. Up to 1 GiB per file. Keep this tab open until your downloads finish.

Batch conversion uses the standard settings. Open Customize a file below to change them.

Conversion starts as soon as you choose files. Files download automatically when ready. Your browser may ask to allow multiple downloads.

Customize a file · settings, paste and edit

CSV → SQL

Free conversion in your browser. Your file stays on this device.

Local processing
8 fictional sales rows · CC0
  1. Choose your CSV

    Open a file, paste CSV text, or try the sample.

  2. Review the preview

    Choose a dialect, operation and column types; check the SQL.

  3. Copy or download

    Save your .sql file with the current settings.

Output preview

Example output
INSERT INTO "csv_data" ("Project", "Status") VALUES (E'Website', E'Ready');
INSERT INTO "csv_data" ("Project", "Status") VALUES (E'Docs', E'In progress');

Preview is limited to the first 20 rows and 16,000 characters. Download includes every row within the tool limits.

Three simple steps

How to convert CSV to SQL

  1. 1. Open your CSV

    Choose several CSV files and convert them together. For column settings, pasted text or editing, open Customize a file. The first row supplies column headers.

  2. 2. Review the output

    Follow each file’s progress. View opens a short preview without leaving the page; use Customize a file when you need different format settings.

  3. 3. Save your result

    Copy the complete output or download a .sql file. Downloads start when files are ready, with a Download button for every result. No signup or payment is required.

Output contract

What the SQL converter writes

Choose PostgreSQL, SQLite or MySQL. Values default to text; explicit numeric types are validated. Choose batch INSERT or key-based UPDATE, DELETE and native upsert. CREATE TABLE is available for insertion; empty-cell NULL conversion is optional. No database connection is required.

The preview is bounded so larger files stay manageable. Downloads use the complete parsed document within the format limits, including changes made in the editor.

Parsing and conversion happen on your device. Your CSV is not uploaded to a conversion server. An error preserves the current input so you can adjust settings or edit the source and try again.

Other ways to convert CSV to SQL

Prefer a script or command line? These examples run on your computer. They create separate files; review their output rules because external tools can handle types and empty values differently from this page.

Create a SQLite SQL script from CSV with Python

Run this on your own computer using Python 3. Save a UTF-8, comma-delimited input.csv in the same folder as the script. The first record must contain unique, nonempty headers; quoted commas and line breaks are parsed as fields.

Before you start

  • Python 3 installed. Package commands below use a local virtual environment on macOS/Linux; on Windows use .venv\Scripts\python.exe in place of .venv/bin/python.
  • Keep the original CSV. These examples read the complete table into memory and create separate output files.
  1. Save the Python code as convert_csv.py beside input.csv.
  2. Install the listed package when required, then run the script. Check the generated output before using it elsewhere.
Save as convert_csv.py
import csv
from pathlib import Path

with open("input.csv", encoding="utf-8-sig", newline="") as source:
    reader = csv.reader(source, strict=True)
    headers = next(reader)
    rows = list(reader)
if not headers or any(not h for h in headers) or len(set(headers)) != len(headers):
    raise ValueError("Use unique, nonempty column headers")
if any(len(row) != len(headers) for row in rows):
    raise ValueError("Every record must have the same number of fields as the header")

import sqlite3
def identifier(name):
    return '"' + name.replace('"', '""') + '"'
with sqlite3.connect(":memory:") as database:
    columns = ", ".join(identifier(header) + " TEXT" for header in headers)
    database.execute("CREATE TABLE records (" + columns + ")")
    placeholders = ", ".join("?" for _ in headers)
    database.executemany("INSERT INTO records VALUES (" + placeholders + ")", rows)
    Path("output.sql").write_text("\n".join(database.iterdump()) + "\n", encoding="utf-8")

Run the conversion
python3 convert_csv.py

Limits and output

  • Writes SQLite CREATE TABLE and INSERT statements wrapped in a transaction. This is a SQLite script, not PostgreSQL or MySQL upsert syntax. Values remain text; empty fields are not converted to NULL. Execute it only in an intended empty SQLite database.

Documentation: Python CSV reader and writer; Python SQLite SQL dump

Plain answers

SQL conversion questions

Is this a real SQL file?

Yes. The download is valid SQL text created from the parsed CSV table.

When is the download created?

The output preview appears after parsing. Copy and download generate the complete output with your current settings; the preview can show fewer rows than the exported file.

What happens to data types?

Cells stay as text by default, preserving identifiers and leading zeroes. SQL and SQLite allow explicit column types; invalid values are reported before download.