01What is CSV to SQL?
Paste CSV with a header row and you get a CREATE TABLE IF NOT EXISTS statement followed by INSERT statements. Pick PostgreSQL, MySQL or SQLite as the target. It's the quick path when you have a spreadsheet export and just want rows in a database without clicking through an import wizard. Column types are inferred from the data. A column whose non-empty values are all true/false/yes/no/1/0 becomes BOOLEAN and is inserted as TRUE or FALSE. SQLite has accepted both keywords since version 3.23, according to its release notes, and stores them as 1 and 0. Whole numbers become INTEGER, then BIGINT once a value passes 2,147,483,647, then DECIMAL(n, 0) beyond the 64-bit range. Decimals become DECIMAL(p, s), where p is the widest integer part plus the widest fractional part, so every value fits. SQLite gets REAL instead. Numbers written with leading zeros, such as ZIP codes and IDs like 00123, are kept as text so the zeros survive. Valid ISO dates become DATE. Timestamps become TIMESTAMP in PostgreSQL, or TIMESTAMPTZ when they carry Z or an offset. In MySQL they become DATETIME, but zone-suffixed values stay text because DATETIME doesn't accept a trailing Z or offset. Everything else is VARCHAR(50), VARCHAR(255) or TEXT, depending on the longest value. Header names and the table name are lowercased, and any character outside letters, digits and underscore turns into an underscore. Empty headers become column_N and duplicates get a _2 suffix. Empty cells and the literal word null become NULL. In string literals single quotes are doubled. For MySQL, backslashes are doubled as well, because the MySQL manual treats backslash as an escape character by default. The CSV parser follows RFC 4180, so quoted fields can hold commas, doubled quotes and line breaks. Here's a small run. In MySQL mode, the input path,note with a row C:\temp,"a, b" produces ('C:\\temp', 'a, b'). A following row of ,null becomes (NULL, NULL). Rows go out in multi-row INSERTs of 100, which keeps each statement a sensible size. Now the limits. The generator only infers types. It adds no primary key, NOT NULL, index or foreign key. Type guesses come from the values you paste, so a sample that happens to hold only 0 and 1 will type as BOOLEAN even if it's really a count. For very large files, a native loader will beat INSERT statements by a wide margin. The parsing and SQL generation happen in your browser tab, so your CSV rows aren't uploaded to our server.
Backend developers, data analysts and students who need to get spreadsheet data into a relational database fast. The tool runs entirely in your browser, so your data never leaves your device.
02How to use CSV to SQL
- Choose a Dialect (PostgreSQL, MySQL or SQLite) and type a name in the Table field.
- Paste CSV into the CSV Input panel, header row first.
- Review the generated CREATE TABLE and INSERT statements in SQL Output.
- Click Copy SQL and run it in psql, the mysql client or sqlite3.
03Worked examples
- Input:
id,name,price,created 1,Widget,9.99,2024-01-15 2,O'Brien Gadget,24.50,2024-02-01 (PostgreSQL, table products) - Result:
CREATE TABLE IF NOT EXISTS "products" ( "id" INTEGER, "name" VARCHAR(50), "price" DECIMAL(4, 2), "created" DATE ); INSERT INTO "products" ("id", "name", "price", "created") VALUES (1, 'Widget', 9.99, '2024-01-15'), (2, 'O''Brien Gadget', 24.50, '2024-02-01'); - The apostrophe in O'Brien is escaped by doubling it, and the decimal precision is sized from the widest value.
- Input:
zip,flag 00123,true 94105,false (MySQL, table t) - Result:
CREATE TABLE IF NOT EXISTS `t` ( `zip` VARCHAR(50), `flag` BOOLEAN ); INSERT INTO `t` (`zip`, `flag`) VALUES ('00123', TRUE), ('94105', FALSE); - Any value with a leading zero makes the whole column text, so ZIP codes keep their zeros. MySQL uses backticks for identifiers.
- Input:
ts,big 2024-03-01T10:00:00Z,9223372036854775808 (PostgreSQL, table events) - Result:
CREATE TABLE IF NOT EXISTS "events" ( "ts" TIMESTAMPTZ, "big" DECIMAL(19, 0) ); … - A timestamp with a Z or offset becomes TIMESTAMPTZ, and an integer one above the BIGINT maximum falls back to DECIMAL.
- Input:
First Name,e-mail Ann,[email protected] (SQLite, table My Table) - Result:
CREATE TABLE IF NOT EXISTS "my_table" ( "first_name" TEXT, "e_mail" TEXT ); INSERT INTO "my_table" ("first_name", "e_mail") VALUES ('Ann', '[email protected]'); - Table and column names are lowercased and spaces and hyphens become underscores.
- Input:
path,note C:\temp,"a, b" ,null (MySQL, table files) - Result:
CREATE TABLE IF NOT EXISTS `files` ( `path` VARCHAR(50), `note` VARCHAR(50) ); INSERT INTO `files` (`path`, `note`) VALUES ('C:\\temp', 'a, b'), (NULL, NULL); - MySQL output doubles the backslash. The quoted field keeps its comma, and an empty cell and the word null both become NULL.
- Input:
ts 2024-03-01T10:00:00+02:00 (MySQL, table m) - Result:
CREATE TABLE IF NOT EXISTS `m` ( `ts` VARCHAR(50) ); … - MySQL DATETIME can't hold an offset, so a zone-suffixed timestamp column stays text (output trimmed).
04Common use cases
- Loading a spreadsheet export into a local Postgres database for a quick analysis
- Turning a product CSV from a client into a seed migration for a Rails or Laravel app
- Creating SQLite fixtures for integration tests
- Moving a Google Sheets table into MySQL without setting up an import wizard
- Checking what types a CSV column will infer before writing the real schema by hand
- Sharing a small reproducible dataset in a bug report as plain SQL that anyone can paste into sqlite3
05Tips
- A column holding only 0 and 1 will be typed BOOLEAN; rename or adjust the type if it's actually a count.
- ID columns without leading zeros still infer as INTEGER; if they are really codes (phone numbers, account numbers), change the column to VARCHAR before running.
- If your MySQL server runs with the NO_BACKSLASH_ESCAPES SQL mode, backslashes in the output will be stored doubled; turn that mode off for the import or undo the doubling.
- Add a PRIMARY KEY and NOT NULL constraints yourself; the generator only infers types.
- For very large files a native loader such as COPY or LOAD DATA INFILE will be much faster than INSERT statements.
06Related concepts
CREATE TABLE, Type inference, SQL dialects, Bulk insert, CSV parsing.
Frequently Asked Questions
What is CSV to SQL?
CSV to SQL is a free, browser-based developer tool on AIDToolStack. Convert CSV to SQL CREATE TABLE + INSERT It requires no installation or sign-up and works entirely in your browser.
Is CSV to SQL free to use?
Yes. No sign-up, no fees and no usage cap.
Does CSV to SQL store my data?
No. It runs in your browser; nothing is uploaded.