Getting a spreadsheet into a database sounds like it should be one click, and often it is — until a date column fails to import, a name with an apostrophe breaks the SQL, or every number arrives as text. This guide covers the three common ways to load CSV data into MySQL, PostgreSQL, SQLite or SQL Server, how to choose column types, and how to go the other way when you need a database dump in Excel.

Option 1: generate INSERT statements

For small and medium files (up to tens of thousands of rows), the most portable method is a SQL script: a CREATE TABLE statement followed by INSERT statements. It runs in any SQL client, can be reviewed before running, and can be committed to version control as seed data.

CREATE TABLE IF NOT EXISTS customers (
  id INT PRIMARY KEY,
  name VARCHAR(255),
  city VARCHAR(255),
  joined DATE
);
INSERT INTO customers (id, name, city, joined) VALUES
  (1, 'Asha Rao', 'Pune', '2025-04-12'),
  (2, 'D''Souza Traders', 'Goa', '2025-06-01');

CSV to SQL builds this script in your browser for MySQL, PostgreSQL, SQLite or SQL Server, quoting identifiers and escaping text correctly for each dialect — note the doubled apostrophe in D''Souza, which is how SQL escapes a single quote. Rows are batched (100 per statement by default) so the script runs quickly without hitting statement-size limits. JSON to SQL does the same for an array of JSON records.

Option 2: the database’s bulk loader

For large files, use the database’s native loader, which is much faster than individual inserts:

  • PostgreSQL: \copy customers FROM 'customers.csv' WITH (FORMAT csv, HEADER true) in psql.
  • MySQL: LOAD DATA LOCAL INFILE 'customers.csv' INTO TABLE customers FIELDS TERMINATED BY ',' ENCLOSED BY '"' IGNORE 1 LINES;
  • SQLite: .import --csv customers.csv customers in the sqlite3 shell.
  • SQL Server: BULK INSERT or the Import Flat File wizard in SSMS.

Bulk loaders need the table to exist first with suitable column types — generate the CREATE TABLE statement with the CSV to SQL tool or JSON to SQL Schema and adjust it.

Option 3: a GUI import wizard

DBeaver, pgAdmin, MySQL Workbench, TablePlus and SSMS all have import wizards. They are convenient for one-off loads but hide decisions about types and encodings; check the preview carefully.

Choosing column types

Type inference looks at the values in each column. Review its choices, because a wrong type either rejects rows or silently corrupts them:

DataTypeWatch out for
Whole numbersINT or BIGINTIDs over 2,147,483,647 need BIGINT
MoneyDECIMAL(12,2) / NUMERICNever FLOAT for currency
Codes with leading zerosVARCHARPIN codes, phone numbers, SKUs
DatesDATE / TIMESTAMPConvert to YYYY-MM-DD first
Yes/noBOOLEAN (BIT in SQL Server)Normalise to true/false or 1/0
Free textVARCHAR(n) or TEXTCheck the longest value

Clean the CSV first

Most import failures come from the file, not the database. Before loading, fix encoding (use UTF-8), remove title and total rows, make dates consistent, strip currency symbols and thousands separators from numbers, and decide how blanks should be stored (empty string or NULL). The CSV Analyzer finds these problems, and the CSV cleaning guide explains each fix.

Going the other way: SQL to CSV or JSON

Database dumps (mysqldump, pg_dump --inserts) are SQL scripts full of INSERT statements. To open that data in Excel without restoring the database, SQL to CSV and SQL to JSON extract the rows from the INSERT statements in your browser. When the database is running, use its own export instead: \copy (SELECT …) TO 'out.csv' CSV HEADER in PostgreSQL, or SELECT … INTO OUTFILE in MySQL.

Keeping SQL readable

Generated and hand-written queries both benefit from consistent formatting: one clause per line, indented column lists and upper-case keywords. Paste long queries into the SQL Formatter before reviewing or committing them. And if you only need answers from a CSV rather than a permanent table, skip the database entirely: SQL Query on CSV runs SQL directly on the file.