Skip to content
SPCX Tools

CSV to SQL

Instantly convert CSV data into SQL CREATE TABLE and INSERT statements.

Runs locally — files never leave your device

Loading tool…

How to use CSV to SQL

  1. 1Paste your CSV data into the input box, or click Sample to see how the formatting works.
  2. 2Enter a target table name and select your preferred database dialect (MySQL, PostgreSQL, SQLite, or SQL Server).
  3. 3Toggle options to include a CREATE TABLE statement, batch your inserts, or treat empty cells as NULL.
  4. 4Copy the generated SQL or download it directly as a .sql file.

A fast, private CSV to SQL converter

Transforming spreadsheet data into a relational database format is a common task for developers, database administrators, and data analysts. This tool allows you to convert CSV to SQL directly in your web browser. Whether you need to seed a new database, migrate legacy records, or quickly import a dataset, you can generate insert statements from CSV data in seconds.

Because the entire conversion process runs locally on your device, your data is never uploaded to an external server. This guarantees complete privacy and security, allowing you to safely process confidential user data, financial records, or proprietary information without risking exposure.

How automatic type inference works

Writing a schema by hand for a dataset with dozens of columns is tedious. To save time, this tool automatically reads your CSV data and infers the most appropriate SQL data type for each column. It looks at the actual values in your rows (skipping empty cells) and applies the following rules:

  • INTEGER: Assigned if every value in the column is a whole number (e.g., 42, -15).
  • DECIMAL: Assigned if the values are floating-point numbers or use scientific notation (e.g., 3.14, -0.5).
  • BOOLEAN: Assigned if the column contains only true or false (case-insensitive).
  • DATE: Assigned if the values match the standard ISO date format (YYYY-MM-DD).
  • TEXT / VARCHAR: The fallback type if a column contains mixed data, plain text, or formats that don't match the strict patterns above.

If you choose to generate a CREATE TABLE statement, these inferred types are automatically mapped to the correct syntax for your chosen database dialect.

Supported SQL dialects

Different database engines have unique rules for quoting identifiers (like table and column names), defining data types, and formatting literal values. This tool supports four major dialects to ensure your generated SQL runs without syntax errors:

MySQL: When you convert CSV to MySQL, the tool wraps table and column names in backticks (`). Text columns default to VARCHAR(255), and booleans are written as TRUE or FALSE.

PostgreSQL: Identifiers are wrapped in double quotes ("). Text columns use the TEXT type, which is standard and highly efficient in Postgres. Booleans are natively supported as TRUE or FALSE.

SQLite: Identifiers use double quotes. Because SQLite uses dynamic typing with a restricted set of storage classes, decimals are mapped to REAL, booleans are mapped to INTEGER (outputting 1 or 0), and text uses the TEXT affinity.

SQL Server (T-SQL): Identifiers are wrapped in square brackets ([]). Text columns default to VARCHAR(255), and booleans are mapped to the BIT data type (outputting 1 or 0). Additionally, if a text string contains non-ASCII characters, the tool automatically prefixes it with N (e.g., N'Value') to ensure proper Unicode (NVARCHAR) insertion.

Customizing your SQL output

You can tailor the generated SQL script to match your exact deployment needs using the configuration toggles:

  • Table name: Define the exact name of the target table. The tool will automatically apply the correct quoting for your dialect.
  • Include CREATE TABLE: If you are building a database from scratch, enable this to generate the schema definition before the insert statements. The tool uses the headers from your CSV as column names.
  • Batch inserts: Running thousands of individual INSERT INTO statements can be slow. Enabling the batch option groups up to 500 rows into a single CSV to SQL insert statement. This drastically reduces the file size and improves import performance.
  • Empty cells as NULL: Spreadsheets often contain blank cells. Checking this option ensures that empty strings in your CSV are explicitly written as the NULL keyword in SQL, rather than inserting empty strings ('') into your database.

Tips for preparing your CSV data

For the best results, ensure your CSV file has a header row. The tool uses the first row of your data to name the columns in the CREATE TABLE and INSERT statements. If a column header is blank, it will be automatically named column_1, column_2, etc.

If your data contains complex text with commas, newlines, or quotes, ensure the CSV is properly formatted (typically by wrapping the field in double quotes). The tool includes a robust CSV parser that correctly handles escaped quotes and multi-line fields.

If you need to process your data in other formats, you might also find our CSV to JSON or CSV to Excel converters useful. Once your SQL is generated, you can run it through a SQL Formatter if you need to adjust the indentation or casing of the keywords.

Frequently asked questions

How does the tool infer SQL data types?
The converter scans the data in each column (ignoring empty cells). If every value matches a specific pattern, it assigns the corresponding type: INTEGER for whole numbers, DECIMAL for floating-point numbers, BOOLEAN for true/false values, and DATE for YYYY-MM-DD formats. If the data is mixed or doesn't match these patterns, it defaults to TEXT or VARCHAR.
Is my CSV data uploaded to a server?
No. All parsing and SQL generation happen locally in your web browser using JavaScript. Your data never leaves your device, making this tool completely safe for sensitive, confidential, or proprietary database records.
What does the "Batch" option do?
When enabled, the tool groups up to 500 rows of data into a single multi-row INSERT statement. This significantly reduces the size of the generated SQL file and speeds up the execution time when you run the script in your database.
How are empty cells handled?
If you check "Empty as NULL", any blank cell in your CSV will be written as the NULL keyword in the SQL output. If unchecked, empty cells are treated as empty strings ('') for text columns, or left as NULL for numeric columns where an empty string would cause a syntax error.
Why do the generated data types change when I switch dialects?
Different database systems use different keywords for column types. For example, a boolean column is represented as BOOLEAN in PostgreSQL, but as BIT in SQL Server and INTEGER in SQLite. The tool automatically adjusts the CREATE TABLE syntax and data formatting to match the selected dialect.