CSV to SQL Converter

This CSV to SQL converter turns a spreadsheet export into INSERT statements you can run on your database. It guesses column types, writes a CREATE TABLE, and quotes values correctly for MySQL, PostgreSQL, SQLite, or SQL Server.

Updated
Runs in your browser. Only SQL text is written; nothing touches a database.
Column types are guessed from the values. Check them before you run the SQL.

How to use the CSV to SQL Converter

  1. Paste CSV or upload a .csv file (up to 5 MB).
  2. Pick the Database, type the Table name, and set how many rows go in each INSERT.
  3. Check the inferred column types, then copy or download the .sql file.

How it works

The CSV is read by the RFC 4180 rules, so quoted values can contain commas, quotes (written as ""), and line breaks. Each column's type is inferred from all its values:

  • Whole numbers only: INTEGER (BIGINT above 2,147,483,647)
  • Numbers with decimals: DECIMAL with enough precision
  • true / false only: BOOLEAN
  • YYYY-MM-DD dates: DATE; with a time: DATETIME or TIMESTAMP
  • Anything else: VARCHAR sized to the longest value

Text is quoted with single quotes, and single quotes inside values are doubled. Identifiers use the quoting of each database: `backticks` for MySQL, "double quotes" for PostgreSQL and SQLite, [brackets] for SQL Server.

Examples

  • id,name / 1,O'Neil → INSERT INTO `my_table` (`id`, `name`) VALUES (1, 'O''Neil');
  • A column with 9.99 and 10.5 becomes DECIMAL(4,2).
  • An empty cell becomes NULL when "Empty cells as NULL" is on.

Loading large files

For a few thousand rows, INSERT statements are fine. For hundreds of thousands, use the database's bulk loader instead: LOAD DATA INFILE in MySQL, COPY in PostgreSQL, .import in SQLite, or BULK INSERT in SQL Server. They are much faster and read the CSV directly.

Limitations

  • Types are guessed from the values in the file. Review them before creating a production table.
  • SQL Server accepts at most 1,000 rows per INSERT, so the batch size is capped at 1,000.
  • Files up to 5 MB.

Frequently asked questions

How do I convert a CSV file to SQL?

Paste or upload the CSV, choose your database and table name, and copy the generated CREATE TABLE and INSERT statements.

Are apostrophes in my data handled?

Yes. A single quote inside a value is doubled (O''Neil), which is the standard SQL escape.

Is my data uploaded?

No. The conversion runs in your browser; the SQL is only text you copy or download.

Often used together with the CSV to SQL Converter.

  • SQL Query GeneratorDeveloper Tools

    Generates CREATE, INSERT, SELECT, UPDATE, and DELETE statements for four databases.

  • SQL FormatterDeveloper Tools

    Formats SQL queries for MySQL, PostgreSQL, SQLite, SQL Server, and more.

  • CSV to JSON

    Turns a CSV table into an array of JSON objects.