CSV to SQL

Generate CREATE TABLE and INSERT statements from CSV data. Supports PostgreSQL, MySQL, SQLite, and SQL Server.

What is CSV to SQL Conversion?

Converting CSV data to SQL is one of the most common data import workflows. Instead of manually writing CREATE TABLE and INSERT statements for hundreds of rows, you paste your CSV and get ready-to-run SQL in seconds. The tool automatically infers the appropriate SQL type for each column — integers, decimals, booleans, or text.

This is useful for seeding databases during development, importing exported spreadsheet data into PostgreSQL or MySQL, migrating flat files into relational databases, and generating test fixtures. The generated SQL includes both the schema definition (CREATE TABLE) and the data (INSERT statements) in your chosen SQL dialect.

Dialect Differences

FeaturePostgreSQLMySQLSQLiteSQL Server
Identifier quoting"column"`column`"column"[column]
String typeTEXTVARCHAR(255)TEXTNVARCHAR(255)
Boolean typeBOOLEANBOOLEANBOOLEANBIT
Integer typeBIGINTBIGINTBIGINTBIGINT

Type Inference Rules

Column valuesInferred SQL typeExample
All integersBIGINT1, 42, 1000
All decimalsDOUBLE PRECISION9.5, 3.14
true / false onlyBOOLEAN (or BIT)true, false
Mixed or stringsTEXT / VARCHAR(255)Alice, 2024-01-01
Empty columnTEXT / NVARCHAR(255)(all empty)

Example Output (PostgreSQL)

sql
CREATE TABLE "users" (
  "name" TEXT,
  "email" TEXT,
  "age" BIGINT,
  "active" BOOLEAN,
  "score" DOUBLE PRECISION
);

INSERT INTO "users" ("name", "email", "age", "active", "score") VALUES ('Alice', 'alice@example.com', 30, TRUE, 9.5);
INSERT INTO "users" ("name", "email", "age", "active", "score") VALUES ('Bob', 'bob@example.com', 27, TRUE, 8.2);

Frequently Asked Questions

Yes — RFC 4180 quoted fields ("value with, comma") are parsed correctly. Double-escaped quotes ("") are also handled.

Currently only comma-separated CSV is supported. For TSV or semicolon-separated files, replace the separator with commas before pasting.

Copy the output and paste it into psql, MySQL Workbench, DBeaver, or any SQL client. Or pipe it: psql -U user -d mydb < output.sql

The tool uses a heuristic based on column values. You can manually edit the CREATE TABLE statement to adjust types before running it.

Related Tools