Skip to content

CSV to SQL Converter — INSERT Statements for MySQL, PostgreSQL, SQLite, SQL Server

Turn a CSV, TSV or Excel file into CREATE TABLE and batched INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server, with detected column types.

CSV, TSV, TXT, XLSX, XLS or ODS, up to 50.00 MB. Read in your browser, not uploaded.

Use schema.table for a schema-qualified name (dbo.customers).

1 = one INSERT per row. SQL Server allows at most 1,000 rows per INSERT, so larger batches are split there.

3 rows · 9 columns · 2 SQL statements
Columns
ColumnTypeSQL typeFirst value
idINTEGER1
nameTEXTO'Brien, Pat
emailTEXTpat@example.com
signup_dateDATE2024-01-15
last_loginTIMESTAMPTZ2024-11-01 09:12:00
planTEXTpro
monthly_feeDECIMAL(4, 2)29.00
activeBOOLEANtrue
notesTEXTSays "hi" a lot

Runs entirely in your browser. Your CSV or Excel file is read locally and is never uploaded. Browse all free tools.

Found a problem, or something that could be better? We read every message and we fix things quickly.

This CSV to SQL converter turns a CSV, TSV or Excel file into a CREATE TABLE statement and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server. Paste the data or open the file, check the column types it detected, and copy or download a .sql file you can run in your database client.

The four databases quote and escape differently, and the converter follows each one: backticks and backslash escapes for MySQL, double-quoted identifiers and doubled quotes for PostgreSQL and SQLite, [brackets] and N'...' Unicode strings for SQL Server, plus TRUE/FALSE or 1/0 for booleans. Types are detected from every row, not a sample, and stay strict: a ZIP code like 02134 stays text, and 1,234 is not guessed to be a number. MySQL and PostgreSQL output was loaded into real MySQL 8 and PostgreSQL 18 servers to check it stores the exact text; SQL Server output follows Microsoft's documentation but was not run against a live server. The limit is 500,000 rows or 50 MB per file, processed in your browser.

How to use

  1. Paste CSV or TSV data, or open a .csv, .tsv, .xlsx, .xls or .ods file (pick the sheet for workbooks).
  2. Choose the database: MySQL / MariaDB, PostgreSQL, SQLite or SQL Server, and set the table name.
  3. Check the detected type of each column and change any that is wrong; values that do not fit the type you choose are listed.
  4. Set the options: header row, empty cells as NULL or empty string, rows per INSERT, CREATE TABLE and a transaction.
  5. Copy the SQL or download it as a .sql file and run it in your database client.

Frequently asked questions

How do I convert a CSV file to SQL INSERT statements?

Open the CSV file or paste its contents, choose your database and enter the table name. The tool writes a CREATE TABLE statement from the column names and detected types, then INSERT statements with every row, grouped 100 rows per statement by default. Copy the result into your SQL client (psql, mysql, SQLite, SSMS, DBeaver) and run it.

How are column types detected?

Every value in a column is checked. If all of them are whole numbers without leading zeros, the column is an integer (BIGINT when a value exceeds the 32-bit range). Numbers with a decimal point give DECIMAL(precision, scale) sized to the data. true/false gives a boolean, YYYY-MM-DD a date, and YYYY-MM-DD HH:MM[:SS] a date-time, with a time zone type when a value has an offset. Anything else is text. Empty cells do not count against a type, and you can override any column.

Why does MySQL output have extra backslashes?

Because MySQL treats the backslash as an escape character inside strings by default. A value like C:\new\table would otherwise be stored with a newline and a tab in it. The converter writes \\ for every backslash and \' for quotes. If your server runs with the NO_BACKSLASH_ESCAPES SQL mode, use the SQLite output instead, which only doubles single quotes.

How many rows can one INSERT statement have?

SQL Server allows at most 1,000 rows in one INSERT ... VALUES list, so the converter splits there even if you ask for more. MySQL is limited by max_allowed_packet (64 MB by default in MySQL 8), and PostgreSQL and SQLite have no practical row limit. Batches of 100 to 1,000 rows load much faster than one INSERT per row; wrap them in a transaction for another speed-up and all-or-nothing behaviour.

Can I convert an Excel file to SQL?

Yes. Open an .xlsx, .xls or .ods file and choose the sheet. Dates in Excel cells become YYYY-MM-DD (or YYYY-MM-DD HH:MM:SS when they have a time) so they are detected as dates, and numbers and booleans keep their values. Formulas give their last calculated value. The Excel reader (about 1 MB) downloads only when you open a workbook.

Is my data uploaded?

No. The file is read by your browser and the SQL is generated there. Nothing is sent to a server, which matters for customer lists and other personal data.

How each database quotes and escapes

• MySQL / MariaDB: identifiers in `backticks`; strings in '...' with \\, \', \", \n, \r, \0 and \Z escaped; booleans TRUE/FALSE (stored as TINYINT(1)).

• PostgreSQL: identifiers in "double quotes"; strings in '...' with quotes doubled (backslashes are literal since standard_conforming_strings became the default in 9.1); TIMESTAMPTZ for values with a time zone. Text cannot hold the NUL character, so it is removed with a warning.

• SQLite: identifiers in "double quotes"; quotes doubled; booleans as 1/0 and dates as ISO 8601 text, which SQLite's date functions read.

• SQL Server: identifiers in [brackets]; strings as N'...' so non-Latin text is not turned into question marks; booleans in BIT columns as 1/0; DATETIME2 or DATETIMEOFFSET for date-times; at most 1,000 rows per INSERT.

Before you run a large import

INSERT statements are the most portable way to move a few thousand rows, but for hundreds of thousands of rows the native bulk loaders are faster: LOAD DATA INFILE in MySQL, COPY or \copy in PostgreSQL, .import in the sqlite3 shell and BULK INSERT or bcp in SQL Server. The CREATE TABLE from this tool is still a good start for those.

Review the generated column types before running the script. Detection only sees the rows you give it: a column that happens to contain only numbers today may need to be text tomorrow (phone numbers, product codes). Add primary keys, NOT NULL constraints and indexes yourself; the converter does not guess them.