What is a CSV to SQL converter?
Importing a CSV into a database usually means either learning the import command of your particular engine or writing INSERT statements by hand. For a few hundred rows, a generated script is quicker: you paste it into a client such as phpMyAdmin, psql, DBeaver or SQL Server Management Studio and press run.
This csv to sql converter does that in the browser. The first line of your CSV becomes the column list. For each column the tool scans the values and picks a type: INT, BIGINT, DECIMAL(15,4), DATE, DATETIME, BOOLEAN, or a VARCHAR sized to the longest value (TEXT above 500 characters). A small table lists each column with a sample value and a drop-down, so you can correct a guess and the SQL regenerates immediately.
Know the limits. The script has no primary key, indexes or constraints. Dates are only recognised in ISO format (2024-01-15). The delimiter is chosen by you; there is no auto-detect. For millions of rows, a database's native bulk loader will be faster than any generated script, and you should always test the output on a copy of the database first.
How to turn a CSV into SQL INSERT statements
- Paste your CSV into CSV Input or press Upload File to load a .csv or .txt file. Load Sample fills in a small example.
- Set the Table Name and choose the SQL Dialect: MySQL, PostgreSQL, SQLite or SQL Server. Set Delimiter if the file is not comma-separated.
- Choose whether to include CREATE TABLE and DROP TABLE IF EXISTS, whether empty cells become NULL, and the Batch Size (rows per INSERT).
- Press Generate SQL. Review the Column Types table and change any type that is wrong; the output updates when you pick a new one.
- Use Copy or Download .sql and run the script in your database client.
What this CSV to SQL generator includes
Four dialects
Identifiers are quoted with backticks for MySQL, double quotes for PostgreSQL and SQLite, and square brackets for SQL Server.
Column type guessing
Whole numbers become INT, or BIGINT beyond 2,147,483,647. Decimals become DECIMAL(15,4). A column with leading zeros, like 02134, stays text so the zeros survive.
Editable type table
Each column shows a sample value and a drop-down with INT, BIGINT, DECIMAL, FLOAT, VARCHAR, TEXT, DATE, DATETIME and BOOLEAN.
Dialect-aware output
SQL Server gets NVARCHAR, BIT and N'' string literals; PostgreSQL gets TIMESTAMP instead of DATETIME; SQLite maps to INTEGER, REAL and TEXT.
Batched inserts
Rows are grouped into multi-row INSERT statements. The default is 100 per statement, and SQL Server is capped at 1,000 rows per statement, its limit.
Safe string escaping
Single quotes are doubled in every dialect, and in MySQL backslashes are doubled too, so values like C:\temp or O'Brien do not break the script.
Who uses it, and for what
- Developers seeding a test database. You have a CSV of fake users and need them in a local PostgreSQL. Generate the script and run it with psql.
- WordPress and PHP site owners. A client sends a product list as CSV. Create the table in phpMyAdmin by pasting the MySQL output, then query it.
- Students learning SQL. Turn a public dataset into a table so you can practise SELECT and JOIN without configuring an import wizard.
- Analysts moving data into SQLite. SQLite output uses simple types, so it is a fast way to put a CSV into a file database for ad hoc queries.
- Support engineers patching data. A short list of corrected values arrives as a spreadsheet. Export it with the Excel to CSV converter, then load it into a staging table here and update the real table with a JOIN.
Tips before you run the SQL
- Rename columns first if the headers contain spaces or symbols. They are quoted, so they work, but clean names are easier to query later.
- Check the types table before copying. A column of codes like 1, 2, 3 will be INT even if you meant text; change it to VARCHAR in the drop-down.
- Keep NULL for empty cells turned on for numeric and date columns. An empty string is not valid in an INT or DATE column in most databases.
- Run the script on a copy or in a transaction first, especially with DROP TABLE IF EXISTS enabled, since it deletes any existing table of that name.
- Use a smaller batch size if your client limits statement length. Very large single statements can hit max_allowed_packet in MySQL.
- Add a primary key yourself afterwards with ALTER TABLE; the generator does not guess keys.
Is it safe? Privacy and limits
The CSV is parsed and the SQL is built entirely in your browser, with no library from a CDN and no upload to a server. The page does not set a file size limit, but large inputs depend on your device's memory. The output is a starting script, not a reviewed migration: check types, quoting and data before running it against a production database.
CSV to SQL converter FAQ
Paste the CSV or upload the file, type a table name, choose your database dialect, and press Generate SQL. The first row is treated as column names, and each remaining row becomes a tuple in an INSERT statement. If you leave Include CREATE TABLE on, the script also starts with a table definition built from the guessed column types. Copy the result or download it as a .sql file and run it in your database client.
It looks at every non-empty value in a column. All true or false becomes BOOLEAN. Whole numbers become INT, or BIGINT if any value exceeds about 2.1 billion. Other numbers become DECIMAL(15,4). Dates in yyyy-mm-dd become DATE, and yyyy-mm-dd with a time becomes DATETIME. Anything else is VARCHAR sized from the longest value, or TEXT above 500 characters. Values with leading zeros stay text. You can override every guess in the Column Types table.
Mostly quoting and type names. MySQL uses backticks, PostgreSQL and SQLite use double quotes, and SQL Server uses square brackets. SQL Server swaps VARCHAR for NVARCHAR, BOOLEAN for BIT, and prefixes strings with N. PostgreSQL turns DATETIME into TIMESTAMP. SQLite reduces types to INTEGER, REAL and TEXT. Booleans are written as TRUE or FALSE for MySQL and PostgreSQL, and 1 or 0 for SQL Server and SQLite. If you are unsure, start with the dialect of the database you will run the script on and compare the first few lines of output.
Up to what your browser can hold in memory. There is no limit written into the tool, but pasting a very large file into a text area, then generating a huge text block, can slow or freeze the tab. As a rule of thumb, tens of thousands of rows are fine; for millions, use LOAD DATA INFILE in MySQL, COPY in PostgreSQL or .import in SQLite, which are built for the job and much faster.
Because the option NULL for empty cells defaults to Yes. In SQL an empty string and NULL are different, and numeric or date columns cannot store an empty string. Switch the option to No if you want empty text columns to hold '' instead. Be careful with that setting for numbers: an empty numeric cell is still written as NULL, since a blank is not a valid number in any of the four databases.
No. The CREATE TABLE statement lists columns and types only, with no PRIMARY KEY, NOT NULL, UNIQUE or index definitions, because a CSV does not say which columns identify a row. Add them after the import with ALTER TABLE, for example ALTER TABLE my_table ADD PRIMARY KEY (id). If you need an auto-increment key, add that column in your database rather than in the CSV. Most teams add keys right after loading the data, once they know the table looks correct.
The tool runs locally and sends nothing to a server, so your rows stay in the tab. Even so, treat any web page with care for credentials or regulated records, and avoid pasting real passwords. Also remember that generated SQL is only as safe as its use: it escapes quotes for string values, but you should still review it before executing it on production data. Replace sample or test data in your CSV with fake values if you only need to demonstrate a problem to someone else.
Export the sheet first with the Excel to CSV converter, then paste it here. To go the other way, SQL to CSV reads INSERT statements, MySQL table output or PostgreSQL COPY text and turns them back into CSV. For other targets from the same data, the CSV to Markdown tool produces a GFM table for documentation. All three tools run in the browser, so you can pass the same data between them without any upload.