CSV to SQL Converter
Turn CSV into CREATE TABLE and INSERT statements for PostgreSQL, MySQL, SQLite or SQL Server, with column types worked out from the data.
Runs in your browser. Nothing is uploaded.
How to use the CSV to SQL Converter
- Paste CSV into the left box, open a .csv file, or press Load example.
- Pick your database (PostgreSQL, MySQL / MariaDB, SQLite or SQL Server) and type the table name.
- Keep Include CREATE TABLE ticked to get a table definition with column types, and set how many rows go in each INSERT.
- Review the SQL on the right. Column names are cleaned up and every value is escaped for your database.
- Copy the SQL or download it as an .sql file and run it in your database client.
From a spreadsheet to database rows
Getting a CSV file into a database is a routine task that is surprisingly fiddly. Import wizards differ between databases, need a running connection and often choke on quoted values, empty cells or unusual headers. Writing INSERT statements by hand is slow and easy to get wrong, especially when names contain apostrophes or numbers have leading zeros.
This converter writes the SQL for you. Paste the CSV, choose the database and table name, and copy a script you can run in psql, the MySQL client, sqlite3, SQL Server Management Studio or any database tool.
What you get
- CREATE TABLE with a column for every heading and a type chosen from the data: integer, decimal, boolean, date-time or text. Turn it off if the table already exists.
- INSERT statements with all rows, grouped by Rows per INSERT.
- Correct quoting for the chosen database: double quotes for PostgreSQL and SQLite, backticks for MySQL, square brackets for SQL Server.
- Escaped values, so apostrophes and other characters are stored exactly as written.
Sensible type detection
With Detect numbers and true/false on, 5000 is written as a number, true as a boolean and an
empty cell as NULL. Values that only look numeric, like IDs with leading zeros, stay as text so their
zeros survive. Turn detection off to write every value as a quoted string and every column as text,
which is useful when loading into a staging table.
Clean names
Headings like Customer ID, Full Name or E-mail address become customer_id, full_name and
e_mail_address. Duplicate headings get a number, and the table name is checked so it is valid SQL
(schema.table is allowed).
Private by design
The tool never connects to a database and nothing is uploaded: the SQL is generated on your device. Check the file first in the CSV Viewer, or start from JSON with JSON Converter.
Frequently asked questions
How are column names chosen?
Headings are turned into safe SQL names in lowercase with underscores, so Customer ID becomes customer_id and Joined On becomes joined_on. Names are also quoted the way your database expects, so reserved words such as order still work.
How are column types decided?
Each column is checked across all rows. Whole numbers become an integer type, decimals a floating-point type, true and false a boolean, and date values a date-time type. Everything else is text. Columns with empty cells allow NULL; full columns are NOT NULL.
Are quotes and special characters safe?
Yes. Single quotes in values are doubled, as SQL requires, so a name like O'Brien is inserted correctly and cannot break the statement.
Why split the INSERT into batches?
One INSERT with thousands of rows can hit statement size limits and is hard to retry. Rows per INSERT groups rows, for example 100 at a time, which is fast and works on every database.
Does the tool connect to my database?
No. It only writes SQL text in your browser. You run it yourself with your usual client, so no credentials or data ever leave your device.
Tutorials
How to import a CSV file into a PostgreSQL or MySQL table
Generate CREATE TABLE and INSERT statements from a CSV of customers, with safe column names, escaped quotes and NULLs, then run them in your database.