About CSV to SQL Converter
Load a spreadsheet export into a database without writing an import script. Paste or open a CSV and this tool writes a CREATE TABLE statement with a type for every column, followed by INSERT statements in batches of the size you choose.
Types are inferred conservatively: a column becomes a number only if every value is one, values with leading zeros stay text, and decimals keep every digit instead of passing through a float. Everything happens in your browser.
How it works
- The CSV is read according to RFC 4180, so quoted fields with commas, quotes and line breaks come through intact. Blank and repeated column names are numbered so no column is lost.
- Each column gets the narrowest type every value fits: integer, big integer, exact decimal, boolean, date, timestamp, or text. One value that does not fit makes the whole column text.
- Names are quoted the way your database expects (double quotes, backticks or square brackets) and text values have their quotes doubled, so a value can never end the statement early.
- Rows are grouped into multi-row INSERT statements. SQL Server accepts at most 1000 rows in one, so larger batches are cut to that.
Questions
Why did my number column come out as text?
At least one value in it is not a plain number: a blank written as a space, a unit, a thousands separator, or a leading zero such as 007. Leading zeros are kept on purpose, because ids and postcodes lose meaning without them.
Are the statements safe to run?
Values are written as quoted literals with their quotes doubled (and backslashes doubled for MySQL), so text like a stray quote or a semicolon stays text. Always check the table name and types before running anything against a real database.
How large a CSV can it handle?
Up to 5 MB of text, which is typically tens of thousands of rows. The SQL it writes is usually two to three times the size of the CSV.
How are empty cells written?
As NULL by default. Turn off "Empty cells become NULL" to write them as empty text instead. A column holding empty text is then typed as text, since an empty string is not a valid number or date.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.