CSV to SQL

Generate CREATE TABLE and INSERT statements from CSV.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

CSV to SQL Converter Online

The CSV to SQL converter generates a ready-to-run SQL script from a CSV file: an optional CREATE TABLE statement with inferred column types, followed by INSERT statements for every row. Paste an export from a spreadsheet, CRM, or analytics tool, choose your database, and copy the script into your SQL client or migration file.

Five SQL dialects

Quoting rules and data types differ between databases, so pick the target dialect:

  • MySQL / MariaDB – backtick identifiers, TINYINT(1) for booleans.
  • PostgreSQL – double-quoted identifiers, native BOOLEAN and TIMESTAMP.
  • SQLite – INTEGER, REAL, and TEXT affinities.
  • SQL Server – bracketed identifiers, NVARCHAR, BIT, and N'…' literals for non-ASCII text.
  • Oracle – NUMBER and VARCHAR2 types, with INSERT ALL for batches.

Options explained

  • Table name – spaces are replaced with underscores and the name is quoted for the dialect.
  • Rows per INSERT – one statement per row is easiest to debug; batches of 100 or 1000 load much faster.
  • CREATE TABLE statement – turn it off when the table already exists and you only need the data.
  • Unquoted numbers & booleans – writes 42 and TRUE/1 instead of '42' and 'true'. Switch it off to insert every value as a string literal.
  • Empty cells as NULL – writes NULL for blank cells rather than an empty string ''.

Type inference in practice

With the sample data the converter detects id as an integer, signup_date as DATE, and active as a boolean, while names and e-mails become VARCHAR(50). Longer text widens the column automatically. Because the guess is based only on the rows you paste, add a representative sample of your data to get sensible sizes.

Typical uses

Seeding a development database, loading a lookup table into a migration, moving data between systems that have no shared import format, or preparing a reproducible bug report with test data.

Design a table by hand with the SQL Table Generator, escape individual strings with SQL Escape, or go the other way with SQL to CSV. Inspect the source file first in the CSV Viewer.

Frequently Asked Questions

Each column is inspected over all rows: whole numbers become INT (or BIGINT for large values), decimals become DECIMAL, true/false columns become the dialect's boolean type, ISO dates become DATE or a timestamp type, and everything else becomes VARCHAR sized to the longest value. Review the types before running the script on production data.

Batching 100 or 1000 rows per INSERT makes imports dramatically faster because the database parses and commits fewer statements. For Oracle, which lacks multi-row VALUES in older versions, the tool writes INSERT ALL … SELECT 1 FROM DUAL instead.

Yes. Single quotes inside values are doubled (O'Brien becomes 'O''Brien'), and identifiers are quoted with the dialect's style — backticks for MySQL, square brackets for SQL Server, and double quotes for PostgreSQL, SQLite, and Oracle.

No. Values like 00501 are kept as quoted strings even when number detection is on, so they are inserted exactly as they appear in the CSV.