CSV to SQL Converter

Convert CSV to SQL INSERT statements with an optional CREATE TABLE for MySQL, PostgreSQL, SQLite or SQL Server, detecting numbers and booleans. Free.

Runs entirely in your browser. Your data is never uploaded.

Related Tools

View All

What is CSV to SQL?

Convert CSV data with a header row into SQL statements: a CREATE TABLE with inferred column types and INSERT statements for every row, quoted and escaped for MySQL, PostgreSQL, SQLite or SQL Server.

How to use CSV to SQL

  1. Paste CSV into the CSV input box, or use Load sample or Open file.
  2. Choose the Delimiter, SQL dialect and Table name.
  3. Toggle Detect numbers and booleans, Include CREATE TABLE and Multi-row INSERT.
  4. The SQL output updates as you type; use Copy or Download.

Example

Input
id,name
1,Ada
2,Bob
Output
CREATE TABLE `my_table` (
  `id` INT,
  `name` VARCHAR(255)
);

INSERT INTO `my_table` (`id`, `name`) VALUES
  (1, 'Ada'),
  (2, 'Bob');

When to use CSV to SQL

Use it for one-off imports when you cannot use a database's native CSV loader (LOAD DATA, COPY, BULK INSERT). For millions of rows those native loaders are much faster.

How CSV to SQL works

The CSV is parsed with PapaParse using the first row as column names. With type detection, a cell becomes a number only if it is a plain integer or decimal without leading zeros (so 007 stays text), true/false become booleans and empty cells become NULL. The same type inference, identifier quoting and string escaping as the JSON to SQL tool is then applied.

Common Use Cases

  • Import a spreadsheet export into a development database
  • Create seed SQL from a CSV in a code review
  • Load reference data (countries, codes) into SQLite
  • Share data as SQL with someone without the CSV tooling

FAQs

Are leading zeros kept?

Yes, values such as 007 or 01234 are kept as strings even with type detection on.

What if my CSV has no header?

A header row is required for column names; add one before converting.

How are empty cells written?

As NULL when type detection is on, or as empty strings when it is off.

Explore more categories