CSV to SQL
Generate SQL INSERT statements from CSV
Uploaded files: up to 400,000 rows (including the header row, files up to 150 MB). Pasted text: up to 65,000 rows. The conversion runs in your browser; the Cancel button stops it.
Click or drop a .csv file hereChoose a .csv file
About CSV to SQL
CSV to SQL writes a CREATE TABLE statement and one INSERT statement per data row from a .csv file or pasted CSV. Pick the database first: Standard SQL (PostgreSQL, SQLite), MySQL / MariaDB, or SQL Server. Table and column names are quoted, and strings escaped, the way that database expects. Column types are sized from your data: INTEGER, BIGINT, or DECIMAL for columns of numbers, VARCHAR (NVARCHAR on SQL Server) as long as the longest value for the others. The tool only writes SQL text; it never connects to a database.
Example
A small CSV pasted with the default table name, and the SQL the tool returns:
CSV
id,name,price 1,Ann,12.5 2,O'Brien,8
SQL
CREATE TABLE "my_table" (
"id" INTEGER,
"name" VARCHAR(7),
"price" DECIMAL(3, 1)
);
INSERT INTO "my_table" ("id", "name", "price") VALUES (1, 'Ann', 12.5);
INSERT INTO "my_table" ("id", "name", "price") VALUES (2, 'O''Brien', 8);How to convert CSV to SQL
- 1Choose the target in "Database" and type a "Table name", or keep my_table.
- 2Add the data: a .csv file through the upload area, or CSV text in "Or paste CSV here".
- 3Make sure "Delimiter:" shows the right separator, and for a file that "Encoding:" shows the right character set.
- 4Click "Convert".
- 5For a file, click "Download" to save converted.sql; for pasted text, the SQL appears in "SQL output" with a "Copy" button.
Formats and limits
- Input
- A .csv file (up to 150 MB) or CSV text pasted in the page
- Output
- SQL text: CREATE TABLE plus one INSERT per row
- Databases
- Standard SQL (PostgreSQL, SQLite), MySQL / MariaDB, SQL Server
- Rows from a file
- 400,000 on a computer, 65,000 on phones and tablets, header row included
- Rows of pasted text
- 65,000 on every device
Where your file is processed
The CSV is parsed and the SQL is written in your browser; your file and pasted data are not uploaded, and no database is contacted. If an error occurs, its wording, cleaned of file names and quoted text, is reported to us with the tool name and your browser version.
Frequently asked questions
Are the column types sized from the data?
Yes. Whole numbers of up to 9 digits give INTEGER, of 10 to 15 digits BIGINT, and decimals DECIMAL with exactly the digits they need. A value with more than 15 significant digits or an exponent makes its column text: VARCHAR (NVARCHAR on SQL Server) as long as the longest value, or TEXT, LONGTEXT, or NVARCHAR(MAX) beyond the limit. Uncheck "Numeric columns as INTEGER / DECIMAL" for text columns only.
Are names with spaces or reserved words safe?
Yes. Every table and column name is quoted for the chosen database: double quotes in Standard SQL, backticks in MySQL / MariaDB, square brackets in SQL Server, with a quote character inside a name doubled. A header such as unit price or order therefore still gives valid SQL.
Are apostrophes in values escaped?
Yes. An apostrophe is doubled, so O'Brien is written 'O''Brien'; MySQL / MariaDB also doubles backslashes, and SQL Server strings get the N prefix. An empty cell becomes NULL in a numeric column and an empty string in a text column.
Is pasted CSV limited to fewer rows than a file?
Yes, on a computer: pasted text stops at 65,000 rows because it lives in the page, while a file can have 400,000 rows and be up to 150 MB. On phones and tablets both limits are 65,000 rows, header row included.
Tips and tricks
- ✓Dates are not detected: change their VARCHAR or NVARCHAR type to DATE or TIMESTAMP in the CREATE TABLE statement before running it.
- ✓To read INSERT statements back into a spreadsheet, use SQL to CSV.
Related tools
- SQL to CSV — the other way: INSERT statements back to CSV rows.
- CSV to JSON — the same CSV as an array of JSON objects.
- CSV to Excel — an .xlsx workbook with real number cells.
- SQL Formatter — put each SQL keyword and column on its own line.
- Excel to CSV