CSV Input

SQL Output

What Is a CSV to SQL Converter?

A CSV to SQL converter turns tabular data from a CSV file (RFC 4180) into SQL statements you can run against a relational database. It reads the first row as column names, then generates a CREATE TABLE statement followed by INSERT INTO statements for every data row. This saves you from writing boilerplate SQL by hand when you want to import data from a spreadsheet or export into MySQL, PostgreSQL, SQLite, or any other SQL database. All columns are typed as VARCHAR(255) — you can adjust types in the generated SQL once you know your schema. Empty cells become NULL, and single quotes inside values are automatically escaped as '' following the SQL INSERT syntax.

How to Use

1

Paste or upload your CSV

Drop your CSV data into the left editor, or click Upload to load a .csv file from disk. The first row must be your column headers.

2

See SQL generated instantly

The tool converts your CSV as you type (debounced 300 ms). The right panel shows a CREATE TABLE block followed by INSERT INTO statements covering all your data rows.

3

Copy or download the SQL

Hit Copy to grab the SQL to your clipboard, or Download to save it as converted.sql. Then run it in your database client or migration tool.

Example

Here's what the conversion looks like with a small users table:

Users CSV → SQL

CSV Input
id,name,email,age
1,Alice,[email protected],30
2,Bob,[email protected],25
3,Carol,[email protected],28

SQL Output:

SQL Output
CREATE TABLE data (
  id VARCHAR(255),
  name VARCHAR(255),
  email VARCHAR(255),
  age VARCHAR(255)
);

INSERT INTO data (id, name, email, age) VALUES
  ('1', 'Alice', '[email protected]', '30'),
  ('2', 'Bob', '[email protected]', '25'),
  ('3', 'Carol', '[email protected]', '28');

Frequently Asked Questions

What SQL databases does this work with?

The generated SQL uses standard ANSI SQL syntax that runs on MySQL, PostgreSQL, SQLite, SQL Server, MariaDB, and most other relational databases. You may need to tweak the VARCHAR(255) column types to match your actual schema.

What happens to empty cells?

Empty cells are converted to NULL. This follows standard SQL practice for missing values. If you need empty string instead of NULL, you can do a quick find-and-replace in your editor after downloading.

Does it handle quoted CSV values with commas inside?

Yes. The parser follows the RFC 4180 CSV spec — values wrapped in double quotes can contain commas and the parser handles them correctly. It also handles escaped double quotes ("" inside a quoted field).

Are single quotes inside values escaped?

Yes. Any single quote character (') inside a cell value is escaped as '' (two single quotes), which is the standard SQL way to include a literal quote in a string. This prevents SQL injection from data values.

Can I change the table name?

The default table name is data. After downloading or copying the SQL, do a quick find-and-replace to use your preferred table name. Future versions may add an editable table name field directly in the UI.

Why are all columns VARCHAR(255)?

CSV files don't carry type information — every value is text. The converter uses VARCHAR(255) as a safe default that works everywhere. Once you have the SQL, change columns to INT, DATE, BOOLEAN, etc. based on your actual data. The MySQL data types reference is a good starting point.

Related Tools