Xerobit

CSV to SQL Converter: Generate INSERT Statements

Paste your CSV data to generate SQL INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server. The converter reads the header row for column names, infers data types, quotes identifiers correctly for each dialect and optionally adds a CREATE TABLE statement. Everything runs in your browser so no data is uploaded anywhere.

First row must be headers. Use commas to separate columns.

SQL Output

INSERT INTO "my_table" ("id", "name") VALUES (1, 'Ann');

How to use the csv to sql converter

  1. Paste your CSV data into the text area, ensuring the first row contains column headers.
  2. Enter the target table name and select your SQL dialect (MySQL, PostgreSQL, SQLite or SQL Server).
  3. Check Include CREATE TABLE if you need the schema generated alongside the insert statements.
  4. Optionally set a batch size greater than zero to group multiple rows into a single INSERT statement.
  5. Copy the generated SQL output directly into your database client or migration script.

How the CSV to SQL conversion works

The converter reads your input as CSV: fields are separated by commas, the first row is the header that defines column names, and a field wrapped in double quotes may contain commas, doubled quotes ("") and even line breaks. For example, given the header id,name,age and a data row 1,Ann,30, the tool maps each value to its column.

Each column is then typed from its values. Whole numbers without leading zeros become INTEGER (BIGINT above nine digits). If every value is a number and at least one has a decimal point, the column becomes DECIMAL(p,s) sized to fit the longest values (NUMERIC in PostgreSQL, REAL in SQLite), so a column holding 95.5 and 88 stays numeric and unquoted. Columns of exactly true or false become BOOLEAN (BIT with 1 and 0 in SQL Server, INTEGER with 1 and 0 in SQLite). Real YYYY-MM-DD dates become DATE, and everything else is text (TEXT, or NVARCHAR(MAX) in SQL Server).

Values with leading zeros such as 007 or 01234 are deliberately kept as text and quoted, because converting them to numbers would drop the zeros. Numbers longer than 18 digits are also kept as text. Type guessing only looks at the data you paste, so review the CREATE TABLE output before using it in production.

Identifier quoting by SQL dialect

Different database engines require different characters to quote table and column identifiers, especially when names contain spaces or match reserved keywords. This csv to sql converter applies the correct quoting automatically based on your selected dialect.

DialectQuote characterExample
MySQLBackticks`my_table`
PostgreSQLDouble quotes"my_table"
SQLiteDouble quotes"my_table"
SQL ServerSquare brackets[my_table]

Embedded quote characters in a name are doubled, so a column called a]b becomes [a]]b] in SQL Server. A table name containing a dot is quoted as one single identifier, not as schema and table. Using the wrong quoting style will cause syntax errors in your database engine, so selecting the correct dialect before converting your CSV to SQL insert statements is essential.

Batching rows into multi-row INSERT statements

By default, the tool generates one INSERT statement per row of data. For large datasets, this produces many individual queries which can slow down execution. Setting the batch size field to a number greater than zero groups that many rows into a single INSERT statement using comma-separated value tuples.

For example, with a batch size of 3 and four rows of data, the output will contain one INSERT statement with three value tuples followed by a second INSERT statement with the remaining single tuple. Multi-row VALUES lists are supported by MySQL, PostgreSQL, SQLite and SQL Server 2008 and later. SQL Server allows at most 1000 row value expressions in a single INSERT, so for the SQL Server dialect this tool automatically caps the batch size at 1000: 1500 rows with a batch size of 2000 come out as one statement of 1000 rows and one of 500. If you leave the batch size at 0, every row gets its own statement ending with a semicolon.

Handling edge cases and ragged rows

A common error when converting CSV to SQL is inconsistent column counts across records, known as ragged rows. If your header has three columns but a record has two or four fields, the converter stops and reports the record number where the mismatch occurs. Duplicate or empty column names in the header are also rejected.

An empty, unquoted cell becomes the SQL keyword NULL. A cell written as an explicit empty quoted field ("") becomes an empty string '', so you can choose between the two in your CSV. Unquoted values are trimmed of surrounding spaces; quoted values are kept exactly as written.

Text is escaped for the selected dialect. Single quotes are doubled in every dialect (O'Brien becomes 'O''Brien'). In MySQL, where a backslash is an escape character by default, backslashes are doubled as well, so a cell such as foo\' OR 1=1 -- stays inside its string literal. SQL Server text uses the N'...' form so non-English characters survive. Escaping makes the generated script safe to paste, but for application code you should still use parameterized queries rather than building SQL from user data.

Integrating with other data formats

Converting CSV to SQL is often just one step in a larger data pipeline. If your source data starts as JSON, you might first convert it to tabular form before generating SQL. Tools like the CSV to JSON converter handle the reverse transformation when you need to export database results back to web APIs.

For developers building typed applications, mapping database schemas to code structures is equally important. Once you have your SQL tables defined, you can use utilities like JSON to TypeScript to generate matching interfaces from sample data. If you are documenting your API layer, formatting your queries with a GraphQL formatter or structuring responses cleanly ensures consistency across your stack.

Worked examples

ExampleInputResult
Basic PostgreSQL INSERTCSV data: id,name / 1,Ann / 2,Bob; Table name: users; SQL dialect: postgres; Include CREATE TABLE statement: no; Rows per INSERT (0 = one per row): 0INSERT INTO "users" ("id", "name") VALUES (1, 'Ann'); / INSERT INTO "users" ("id", "name") VALUES (2, 'Bob');
MySQL with CREATE TABLECSV data: id,name,score / 1,Alice,95.5 / 2,O'Brien,88; Table name: players; SQL dialect: mysql; Include CREATE TABLE statement: yes; Rows per INSERT (0 = one per row): 0CREATE TABLE `players` ( / `id` INTEGER, / `name` TEXT, / `score` DECIMAL(3,1) / ); / INSERT INTO `players` (`id`, `name`, `score`) VALUES (1, 'Alice', 95.5); / INSERT INTO `players` (`id`, `name`, `score`) VALUES (2, 'O''Brien', 88);
Batched SQLite insertsCSV data: id,val / 1,a / 2,b / 3,c / 4,d; Table name: items; SQL dialect: sqlite; Include CREATE TABLE statement: no; Rows per INSERT (0 = one per row): 2INSERT INTO "items" ("id", "val") VALUES (1, 'a'), (2, 'b'); / INSERT INTO "items" ("id", "val") VALUES (3, 'c'), (4, 'd');
Leading zeros stay textCSV data: id,zip / 1,01234 / 2,90210; Table name: places; SQL dialect: postgres; Include CREATE TABLE statement: yes; Rows per INSERT (0 = one per row): 0CREATE TABLE "places" ( / "id" INTEGER, / "zip" TEXT / ); / INSERT INTO "places" ("id", "zip") VALUES (1, '01234'); / INSERT INTO "places" ("id", "zip") VALUES (2, '90210');

FAQ

Does this tool upload my CSV data to a server?

No. The entire csv to sql conversion happens locally in your browser using JavaScript. Your data never leaves your machine and is never sent to any server.

How are single quotes handled in text values?

Single quotes within text values are doubled in every dialect, so O'Brien becomes 'O''Brien'. For MySQL, backslashes are also doubled because MySQL treats backslash as an escape character by default. SQL Server text is written as N'...'.

What happens if my CSV rows have different numbers of columns?

The converter checks every record against the header column count. If a record has too many or too few fields, it returns an error naming the record number so you can fix the inconsistency.

Can I generate both CREATE TABLE and INSERT statements together?

Yes. Check the Include CREATE TABLE option and the tool will output a CREATE TABLE statement with inferred column types followed by the INSERT statements for your data.

How does the type inference decide between INTEGER and DECIMAL?

If every non-empty value is a whole number without leading zeros, the type is INTEGER (BIGINT for long values). If every value is a number and at least one has a decimal point, the column is DECIMAL(p,s) (NUMERIC in PostgreSQL, REAL in SQLite) and numbers stay unquoted. Anything else, including values like 007 or 01234, stays text.

What batch size should I use for large CSV files?

A batch size between 100 and 1000 is typically efficient for most databases. Larger batches reduce the number of round trips but consume more memory during execution. For SQL Server the limit is 1000 rows per INSERT, so larger values are capped at 1000 automatically. Leave it at 0 for one statement per row.

Which SQL dialects are supported for identifier quoting?

The tool supports MySQL (backticks), PostgreSQL (double quotes), SQLite (double quotes) and SQL Server (square brackets). Select the correct dialect to ensure your generated SQL runs without syntax errors.

How do I insert an empty string instead of NULL?

Write the cell as an empty quoted field, for example 1,"" . An empty field with nothing between the commas becomes NULL.

Can the CSV contain commas or line breaks inside a value?

Yes. Wrap the field in double quotes, and write a literal double quote as two double quotes, as in standard CSV.