CSV to SQL Converter
Convert CSV to SQL CREATE TABLE and INSERT statements for PostgreSQL, MySQL, SQLite, or SQL Server, with inferred column types and batched multi-row inserts.
Processed locally in your browser — nothing is uploaded.
CSV to SQL Converter
0 characters
SQL
Output appears here…About the CSV to SQL Converter
Paste CSV and get SQL that loads it: a CREATE TABLE with a type for every column, followed by INSERT statements for the rows. Pick PostgreSQL, MySQL, SQLite, or SQL Server, and identifiers are quoted the way that database expects — "name", `name`, or [name] — with matching type names and boolean values.
Column types are inferred from the data: integers (BIGINT once a value passes the 32-bit range, except in SQLite, whose INTEGER is already 64-bit), decimals with a precision and scale wide enough for every value, booleans, dates, timestamps, and text — sized as VARCHAR or NVARCHAR from the longest value in MySQL and SQL Server. Header names become unique snake_case identifiers, empty cells become NULL, and quotes inside values are escaped.
The CSV parser handles quoted fields, commas and line breaks inside quotes, and auto-detects comma, semicolon, tab, and pipe delimiters. You can also rename the table (optionally with a schema, like sales.orders), skip CREATE TABLE, add DROP TABLE IF EXISTS, treat the first row as data, and choose how many rows go in each INSERT.
Common uses
- Load a spreadsheet export into a database without an import wizard
- Turn a CSV fixture into seed data for tests or a local dev database
- Draft a table definition from a sample of the data it will hold
Example
Input
id,name,joined 1,Ada,2024-01-15 2,O'Neil,
Output
CREATE TABLE "imported_data" (
"id" INTEGER,
"name" TEXT,
"joined" DATE
);
INSERT INTO "imported_data" ("id", "name", "joined") VALUES
(1, 'Ada', '2024-01-15'),
(2, 'O''Neil', NULL);PostgreSQL output. The apostrophe in O'Neil is doubled, and the empty date becomes NULL.
Limitations
- Inferred types are a starting point: they fit the values in this file, not every value the table may hold later, so review lengths and numeric precision before using them in production
- No primary keys, indexes, NOT NULL, or other constraints are added
- Only ISO dates (2024-01-15) and timestamps (2024-01-15 09:30:00) are recognized; other date formats stay text
- An empty cell always becomes NULL, so there is no way to insert an empty string
- Very large files are better loaded with the database's own bulk import, such as PostgreSQL's COPY or MySQL's LOAD DATA
Frequently asked questions
How are column types chosen?
Each column's non-empty cells are checked in turn. If every value is a whole number the column is an integer, if they mix whole numbers and decimals it is a decimal sized to fit them all, true and false values make a boolean, and ISO dates and timestamps get date types. Anything that fits none of those — or values with leading zeros, like ZIP codes — becomes text.
Why are SQLite dates written as TEXT?
SQLite has no dedicated date or time storage class. Its date and time functions work on ISO 8601 text such as 2024-01-15, so storing dates as TEXT keeps them readable and usable in queries. Booleans become INTEGER 1 and 0 for the same reason.
What does rows per INSERT change?
It sets how many rows share one INSERT statement through a multi-row VALUES list. Larger batches usually load faster and make a shorter file; a value of 1 writes one INSERT per row, which is easier to debug when a single row fails. SQL Server allows at most 1000 rows in one VALUES list, so batches are capped there.
How are header names turned into column names?
They are lower-cased and converted to snake_case: accents are removed (Café becomes cafe), letters from other scripts are kept, and symbols and spaces become underscores. Blank headers become column_1, column_2, and so on, and repeated names get a suffix like name_2. Every identifier is also quoted, so reserved words like "order" are safe.
Why does the MySQL output double backslashes?
By default MySQL treats a backslash inside a string literal as an escape character, so the \t in C:\temp would be read as a tab. The converter writes it as C:\\temp, which MySQL stores as the original text. The other dialects treat backslashes literally and leave them alone.
Is my CSV uploaded to a server?
No. Parsing and SQL generation happen entirely in your browser, so the data never leaves your device.