CSV to SQL Converter
Turn correctly quoted CSV into a safer MySQL script with CREATE TABLE and INSERT statements.
-
1Enter data
Enter content, paste text or load a file from disk. -
2Click the button
The tool will immediately process your data in the browser. -
3Get the result
Copy the finished text or save the file to your device.
return "Result ready in 0.1s";
}
The parser supports quoted fields, commas, and multiline records. Empty fields and the text NULL become NULL when inference is enabled. Literals are escaped for MySQL; always review the output before importing it.
Rate this tool:
Related tools
Other tools you may find usefulCSV to SQL converter — from tabular input to INSERT statements
The CSV to SQL converter reads headers and records separated by a comma, semicolon, or tab, then builds a MySQL script. It can include a CREATE TABLE definition and produce individual or batch INSERT statements. The interface runs online, but the component never connects to the target database or executes its output.
Paste the first record with field names together with the data. The parser follows CSV quoting rules: a comma inside a field must be enclosed in double quotes, and a quote is represented by two quotes. CRLF endings and quoted text spanning multiple lines are supported. If you only need to inspect a table before generating commands, open the online CSV viewer.
How the parser handles records, quotes, and multiline fields
A record is not split by simply searching for a newline. A stream parser reads complete fields, so "Austin, Texas" remains one cell and a quoted description can continue on another physical line. Blank physical lines are skipped, while an empty field keeps its position. Every record must have exactly as many fields as the header; a mismatch stops conversion rather than shifting values into the wrong columns.
Headers are normalized into conservative ASCII identifiers accepted by MySQL. Spaces and special characters become underscores, a name beginning with a digit gets a safe prefix, and duplicates created by normalization receive numbered suffixes. This protects the syntax, but you should still confirm that the resulting names match the target schema.
Type inference and CREATE TABLE behavior
When inference is enabled, all nonempty values in a column are considered together. One word cannot accidentally force a numeric type, and an integer in a column of prices does not prevent a decimal type. Empty values and the text NULL do not influence the selected type. Numbers with leading zeros, unusual identifiers, and integers outside a safe range remain text so their representation is preserved.
| Column values | Generated type | Important detail |
|---|---|---|
only true/false | TINYINT(1) | INSERT uses 1 or 0 |
| in-range whole numbers | BIGINT | leading zeros make the column text |
| numbers with a fraction | DECIMAL(p,s) | precision and scale come from the data |
| short text | VARCHAR(255) | suitable for names and codes |
| long or multiline text | TEXT / LONGTEXT | avoids truncation at 255 characters |
With inference disabled, every column is treated as text. That is often the right choice for postal codes, catalog numbers, and identifiers whose exact spelling matters. For manual control over one row, use the SQL INSERT statement generator.
Individual and batch INSERT modes
Individual mode creates one command per record. It is easy to read, makes a bad row easier to locate, and lets you run only part of a script. Batch mode uses one VALUES (...), (...) list and generally reduces import overhead. A large load should still be divided into transactions with the server packet limit in mind. The converter caps input at 1 MB and 5,000 data records to prevent an accidental paste from exhausting a request.
- Select the delimiter used by the file and paste headers with the records.
- Set the table name and choose whether to add
CREATE TABLEand infer types. - Choose individual statements or one batch
INSERT. - Copy the result and review types, names,
NULLvalues, and encoding. - Run it in a test database and a transaction before using a target environment.
Value escaping and reducing SQL injection risk
The result targets MySQL. Identifiers are restricted to letters, digits, and underscores and enclosed in backticks. Text escaping doubles apostrophes and protects backslashes, null bytes, line feeds, carriage returns, and Control-Z. A value such as O'Brien cannot terminate its literal, and a multiline description cannot break the statement. The text NULL becomes the SQL keyword only when inference is on; otherwise it remains a quoted string.
After copying, you can standardize the layout with the SQL formatter. Check the target dialect as well: backticks and TINYINT(1) are MySQL conventions, while PostgreSQL needs different identifiers and some different types. The converter does not invent primary keys, indexes, UNIQUE constraints, relationships, engines, or collations because those belong to the database design rather than a CSV sample.
Quality checks before an import
The most common mistakes are semantic rather than escaping failures: a decimal comma may be confused with a delimiter, dates can use several conventions, and an empty string does not always mean missing data. Compare the record and column counters above the result with the source. Review UTF-8 encoding, normalized names, maximum text length, and monetary precision. If the next stage needs JSON, independently inspect the data with the CSV to JSON converter.
Frequently asked questions
Can a comma or newline appear inside a field?
Yes. Enclose the field in double quotes according to CSV rules. The parser reads multiline records and does not split them with a simple newline expression.
How are empty fields and the word NULL handled?
An empty field becomes NULL. With inference enabled, case-insensitive text NULL also becomes SQL NULL; with inference disabled it is emitted as quoted text.
Is the result resistant to SQL injection?
Identifiers are normalized and text is escaped for MySQL, preventing an apostrophe or backslash from closing a literal. The result is still an executable script that needs review; application code should use parameters.
Why is a postal code or number with a leading zero treated as text?
A value such as 00123 is not inferred as a number because conversion would remove meaningful zeros. A text column preserves its original representation.
Will the generated SQL run on PostgreSQL or SQLite?
Not with a guarantee. The script targets MySQL identifiers and types. Much of the data quoting is similar, but the table definition must be adapted to the chosen engine.