CSV to SQL

Generate SQL INSERT statements from CSV. Delimiter, encoding, table name, first row as columns. Download or copy. 100% client-side.

Related Tools

What This CSV to SQL Tool Offers

This free CSV to SQL tool runs in your browser. Paste or upload CSV, choose delimiter (including auto-detect) and encoding, set the target table name, and optionally use the first row as column names. The tool generates one INSERT statement per data row. Download the .sql file or copy to clipboard. All processing is client-side.

  • Generate INSERT statements: Each CSV data row becomes one INSERT INTO table_name (col1, col2, ...) VALUES (...); statement. Single quotes in values are escaped for SQL.
  • Auto or custom delimiter: Choose Auto to detect the delimiter from the first line, or pick comma, semicolon, tab, or pipe.
  • Encoding for file upload: When you upload a file, select UTF-8, Windows-1252, or ISO-8859-1 so CSVs from different regions or legacy exports are read correctly.
  • Custom table name: Enter the target table name. Invalid characters are replaced with underscores so the name is a valid SQL identifier.
  • First row as column names: When enabled, the first CSV row becomes the column names in the INSERT. When disabled, columns are named col_0, col_1, and so on. Names are sanitized for SQL.
  • Paste or upload: Paste CSV directly into the text area or upload a file via drag-and-drop or file picker.
  • Download and copy: Download the result as a .sql file or copy the SQL to the clipboard.
  • Quoted fields: The parser handles quoted CSV fields and escaped quotes correctly.
  • Client-side and private: Generation happens in your browser; nothing is sent to a server.

Why Convert CSV to SQL?

INSERT statements let you load CSV data into MySQL, PostgreSQL, SQLite, SQL Server, and other databases. Generating SQL from CSV is useful for one-off imports, scripts, or when you do not have direct bulk-load access.

  • Database import: Run the generated .sql file or paste into a SQL client to insert rows into a table.
  • Scripts and migrations: Use the output in migration scripts or seed data for development and testing.
  • No server: Generation runs in your browser, so sensitive data never leaves your device.

How CSV to SQL Generation Works

Your CSV is parsed with the chosen delimiter and encoding. The first row (if used as header) becomes the column list; each following row becomes one INSERT statement. Table and column names are sanitized; string values are wrapped in single quotes with internal quotes escaped.

  • Parse CSV: The tool reads the pasted or uploaded CSV with the selected delimiter (auto-detected if set) and encoding. Quoted fields are handled correctly.
  • Sanitize names: Table name and column names are converted to valid SQL identifiers: invalid characters are replaced with underscores.
  • Escape values: Each cell value is output as a SQL string literal. Single quotes inside values are escaped as two single quotes.
  • One INSERT per row: Each data row produces one INSERT INTO ... VALUES (...); statement. Download or copy the full SQL.

Options Explained

These options control how the CSV is read and how the SQL is built.

  • Delimiter (Auto or manual): Auto detects the separator from the first line (comma, semicolon, tab, or pipe). Choose a specific delimiter when Auto does not match your file.
  • Encoding (file upload): UTF-8 is the default. Use Windows-1252 or ISO-8859-1 for CSVs that show wrong characters when read as UTF-8.
  • Table name: The name used in INSERT INTO table_name. Only letters, numbers, and underscores are kept; other characters are replaced with underscores.
  • First row as column names: When enabled, the first CSV row becomes the column names in the INSERT. When disabled, columns are named col_0, col_1, etc. Names are sanitized to valid identifiers.

When to Use Each Delimiter

Use Auto for most files. If the generated SQL looks wrong (e.g. too few or too many columns), set the delimiter explicitly.

  • Comma: Standard for CSV. Auto usually detects it.
  • Semicolon: Common in European locales. Choose if your CSV uses semicolons.
  • Tab: Used for TSV. Choose when fields are tab-separated.
  • Pipe: Often used in data pipelines. Choose when fields are pipe-separated.

Powered by browser APIs and client-side processing.

Frequently Asked Questions

What SQL does the tool generate?

The tool generates one INSERT INTO table_name (col1, col2, ...) VALUES ('val1', 'val2', ...); statement per CSV data row. Single quotes in values are escaped as two single quotes. Column names and table name are sanitized to valid SQL identifiers.

What does First row as column names do?

When enabled, the first row of the CSV becomes the column names in the INSERT statements (e.g. name, email). When disabled, columns are named col_0, col_1, etc. Invalid characters in header names are replaced with underscores.

What delimiters are supported?

You can use Auto to detect the delimiter from the first line (comma, semicolon, tab, or pipe), or choose a specific delimiter. The same delimiter is used to parse the CSV.

What encoding is used for file upload?

You can select UTF-8 (default), Windows-1252, or ISO-8859-1 when uploading a file. Use Windows-1252 or ISO-8859-1 if the file shows wrong characters with UTF-8.

Is my data secure?

Yes. Generation runs entirely in your browser. Your data never leaves your device and is not uploaded to any server.

Which databases can use this SQL?

The generated INSERT statements use standard SQL syntax. They work in MySQL, PostgreSQL, SQLite, SQL Server, and other databases that support INSERT INTO ... VALUES (...). You may need to adjust for database-specific limits (e.g. max query length) by splitting the file.