Skip to content
Free · Runs in your browser

CSV to SQL converter

Turn a CSV or Excel file into CREATE TABLE and INSERT statements for PostgreSQL, MySQL, SQL Server or SQLite. Your file never leaves your browser.

Works with
CSVTSVXLSXSQL
Opens inPostgreSQLMySQLSQL Server

Drop a CSV or Excel file here

CSV, TSV or .xlsx, up to 100 MB. It stays on your computer.

  • No sign-up
  • Nothing uploaded
  • Column types picked for you
  • Arla Foods logo
  • Bacardi logo
  • British American Tobacco logo
  • Everest Detection logo
  • Golden Acre logo
  • Handlangers logo
  • Inspired Learning Group logo
  • Kantar logo
  • MUFG logo
  • NielsenIQ logo
  • PTI Digital logo
  • RethinkFirst logo
  • Starbucks logo
  • The Specialist Works logo
What you get

A script you can run as it is.

  • Your file stays on your computer

    The SQL is written in your browser. Nothing is sent to Mammoth or anyone else.

  • Written for your database

    PostgreSQL, MySQL, SQL Server and SQLite each quote names, type columns and write true/false their own way. Pick yours.

  • Column types from your data

    Totals become DECIMAL, IDs become INTEGER, dates become DATE, and a code column like 02134 stays text.

How it works

How to convert CSV to SQL

The header row names the columns, every value decides its column's type, and the rows go in as INSERT statements of 500.

  1. 1

    Add your file

    Drop a CSV or Excel file on the box, choose one, or paste CSV in.

  2. 2

    Pick the database

    Choose PostgreSQL, MySQL, SQL Server or SQLite and name the table.

  3. 3

    Download or copy

    Save the .sql file, or copy it into your SQL editor and run it.

Your options

Other ways to do it

Every database has its own loader. They are fast, but each needs the table made first, by hand.

  • Your database's bulk loader

    Big files, a table that exists

    • Writes CREATE TABLE for youNo
    • Picks column typesNo
    • No code or installNo
    • Runs on a scheduleYes
  • Python with pandas

    A job you script once

    • Writes CREATE TABLE for youYes
    • Picks column typesYes
    • No code or installNo
    • Runs on a scheduleYes
  • This page

    This converter

    A file you need in a database now

    • Writes CREATE TABLE for youYes
    • Picks column typesYes
    • No code or installYes
    • Runs on a scheduleNo
Other ways

How to import a CSV into a database

Each database has a bulk loader: COPY or \copy in PostgreSQL, LOAD DATA INFILE in MySQL, BULK INSERT in SQL Server. They need the table to exist first. For SQLite, or with Python, these two lines do the whole job.

Need the data as JSON for an API instead? Use the CSV to JSON converter.

SQLite command line
sqlite3 shop.db ".import --csv orders.csv orders"

Creates the table from the header row, but every column is TEXT, so totals sort as text.

Python with pandas
import sqlite3
import pandas as pd

pd.read_csv("orders.csv").to_sql("orders", sqlite3.connect("shop.db"), index=False)

pandas picks the column types. For PostgreSQL or MySQL, pass a SQLAlchemy engine instead of the sqlite3 connection.

Your file stays private

The converter runs inside this page. Your file is read and written out as SQL on your computer, and nothing is sent to Mammoth. That makes it safe for customer and payment records.

How we handle your data

Once the page has loaded, it works with your internet switched off.

Every month

Loading CSV files into a database every week?

Mammoth can do it for you. Put the files in a folder, and the combined table is appended or upserted into PostgreSQL, MySQL or SQL Server on a schedule.

Try Mammoth free

Partner files

Acmeacme.csv
Borelborel.csv
Catocato.xlsx
DriveDropboxOneDriveSFTP
orders (PostgreSQL)Up to date
Nov 02Order 1041129.50
Nov 02Order 551264.00
Nov 03Order 90201,480.00
Nov 09Order 1077310.25
Nov 09Order 553092.10

Illustration. Every new file in the folder is added to the same table.

Questions

CSV to SQL questions

Is my CSV sent anywhere?
No. The SQL is written inside your browser. Once the page has loaded, it works with your internet switched off.
Which databases does it write for?
PostgreSQL, MySQL (and MariaDB), SQL Server and SQLite. Each gets its own quoting for names, its own column types and its own way of writing true and false.
How are the column types chosen?
From every value in the column. Whole numbers become INTEGER, or BIGINT past 2,147,483,647. Decimals become NUMERIC or DECIMAL sized to the widest value. ISO dates become DATE, date-times become TIMESTAMP or DATETIME, true/false becomes BOOLEAN or BIT, and anything else is text.
Are quotes and apostrophes escaped?
Yes. O'Neill is written as 'O''Neill', backslashes are escaped for MySQL, and text with accents is written as N'…' for SQL Server so it isn't mangled.
How many rows go in each INSERT?
500. One statement per row is slow to run, and SQL Server refuses more than 1,000 rows in a single VALUES list.
Can I convert an Excel file to SQL?
Yes. Drop an .xlsx file on the same box and pick the sheet. Dates in the sheet come through as dates.
Can I leave out CREATE TABLE?
Yes. Untick Include CREATE TABLE to get only the INSERT statements, for a table that already exists. The column names come from the header row, so they need to match.
Is there a size limit?
Files up to 100 MB. For a file much larger than that, your database's own bulk loader is faster: COPY in PostgreSQL, LOAD DATA in MySQL, BULK INSERT in SQL Server.
Is it free?
Yes, with no account and no email.