CSV to SQL Converter
Turn spreadsheet data into SQL you can run. Paste a CSV file and get CREATE TABLE plus INSERT statements, with column types inferred from the values and support for MySQL, PostgreSQL, SQLite and SQL Server dialects.
The reverse direction is the SQL to CSV Converter, and the table definition itself comes from the JSON Schema Generator approach. To load the data as JSON instead, the CSV to JSON Converter is the alternative.
How to use the CSV to SQL
- 1 Paste your CSV, or load a file.
- 2 Set the table name and the column names.
- 3 Choose the target dialect so quoting and types are correct.
- 4 Copy the generated insert statements.
Preparing data for import
The conversion is straightforward once the target schema is known, and fragile when it is not. Column order must match, types must be compatible, and the identifier quoting must match the dialect, since the same table name is quoted differently across engines.
For anything beyond a small file, the generated statements are a starting point rather than the mechanism. A bulk loader is faster and handles errors better, and it is what a database expects for large volumes. Generating SQL is for the cases where no loader is available.
- Batch multiple rows per statement for speed.
- Match the quoting style to the database dialect.
- Empty cells need an explicit decision: empty string or null.
- Escape the quote character inside string values.
Notes on Safety
String values are escaped by doubling single quotes, which is the standard SQL escape. This is fine for generating migration scripts and fixtures. For runtime queries that mix user input, always prefer parameterised statements in your application code instead of building SQL by hand.
Frequently asked questions
How should values be typed?
By matching the destination column. A CSV has no types, so the converter has to guess or be told. Quoting a numeric column makes the value a string, which some engines will coerce and others will reject. Reading the table schema first and declaring the types is the reliable approach.
What is the fastest way to insert many rows?
By batching several rows into a single insert statement rather than emitting one statement per row. The overhead is per statement rather than per row, so a multi-row insert is dramatically faster on any real volume. There is a limit on statement size, which is why the batching is usually configurable.
How do I handle values that are NULL?
By deciding what an empty cell means. In CSV an empty field is genuinely ambiguous: it could be an empty string, a null, or a missing value. The SQL keywords for null is unquoted, whereas an empty string is quoted, so the converter's setting for this determines the semantics of the imported data.
Related Developer Tools
You might also need
Tools from other categories that people pair with the CSV to SQL: