CSV to SQL Converter
Turn CSV into INSERT statements with values escaped, column types inferred and an optional CREATE TABLE.
About this conversion
Import from File
Drag & drop a file here
or
Supports .txt, .csv, .log, .json and other text files
Everything is generated in your browser. The escaping produces valid SQL literals, but this is for loading data you trust — never build runtime queries this way, use bound parameters.
What It Does
Paste a CSV and get SQL you can run to load it. The statements come with values escaped properly — single quotes doubled, numbers left unquoted, empty cells turned into NULL rather than empty strings — and optionally a CREATE TABLE derived from the data. The type inference is deliberately cautious. A column becomes INTEGER only when every value in it is genuinely a whole number, and anything ambiguous falls back to text, because guessing a narrow type that one row violates fails the entire import. Values with leading zeros stay text for the same reason: a postcode of 01234 turned into a number is destroyed rather than converted. Batch size is adjustable, since one row per statement is easiest to debug while batching is far faster for a large load.
When to Use It
- A spreadsheet of reference data needs loading into a new table and you would rather not configure an import wizard.
- You need seed data for a development database and have the values in a CSV already.
- A client sent a data export and you want to see what schema it implies before designing the real one.
- You are moving a lookup table between systems and need portable SQL rather than a database-specific dump.
- A migration needs a one-off data load and you want the statements in version control rather than run by hand.
Worked Examples
id,name,price,active
1,Widget,9.99,true
2,Gadget,19.50,false
Clean inference: id becomes INTEGER, price DECIMAL, active BOOLEAN and name a VARCHAR. Numbers and booleans are emitted unquoted, which is what makes the types actually apply.
code,postcode,qty
A1,01234,5
B2,00987,12
The leading-zero case. Both code columns stay text and the inferred type is VARCHAR, because turning 01234 into a number would silently destroy the value.
name,note
Jane,"O'Brien said ""hello"""
Sam,
Escaping under pressure. The apostrophe is doubled so the literal is valid, the embedded quotes survive the CSV parsing, and Sam's empty note becomes NULL rather than an empty string.
Features
How to Use
1. Paste your CSV or import a file. 2. Set the table name. 3. Choose your dialect so identifiers are quoted correctly. 4. Turn on CREATE TABLE if you need the schema as well as the data. 5. Adjust the batch size — one row per statement for debugging, more for speed — then copy the SQL.
Common Mistakes
- Treating generated SQL as safe for user input. The escaping is correct for building a literal, but runtime queries need bound parameters — escaping is not a substitute for parameterisation.
- Letting an identifier be inferred as a number. Postcodes, phone numbers and product codes with leading zeros are text, and converting them loses information permanently.
- Running the generated CREATE TABLE as a finished schema. It has no primary key, no indexes and no constraints — it is a starting point to edit, not a design.
- Batching too aggressively. Very large multi-row inserts can exceed the server's maximum packet size, and a failure at that point tells you very little about which row was at fault.
- Not noticing that empty cells become NULL. NULL and an empty string behave differently in comparisons, and the difference surfaces much later than the import.