Menu

How to Convert Excel Data to SQL INSERT Statements

Convert Excel or Google Sheets data into SQL CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite, SQL Server, and Oracle.

Posted on By
On this page

Spreadsheet data often needs to become database seed data, lookup tables, test fixtures, or a small one-time import.

You do not have to write one INSERT statement per row manually.

Copy data from Excel or Google Sheets, or export the sheet as CSV, then use the SQLiz CSV to SQL Converter to generate SQL.

Option 1: Copy cells directly from Excel

Suppose your spreadsheet contains:

id name department
1 Ada Engineering
2 Grace Platform
3 Alan Research

Copy the cells including the header row.

Excel normally places tab characters between copied columns, which the converter can parse.

Generated SQL might be:

CREATE TABLE employees (
  id INTEGER,
  name TEXT,
  department TEXT
);

INSERT INTO employees (id, name, department)
VALUES
  (1, 'Ada', 'Engineering'),
  (2, 'Grace', 'Platform'),
  (3, 'Alan', 'Research');

Option 2: Export Excel as CSV

For larger sheets, use Excel’s CSV export and open the resulting file in the CSV to SQL Converter.

The tool supports common delimiters including:

  • comma
  • tab
  • semicolon
  • pipe

It also handles quoted CSV fields containing commas and line breaks.

Choose the target database

SQL syntax and data types vary by database.

The converter supports:

  • SQLite
  • MySQL / MariaDB
  • PostgreSQL
  • SQL Server
  • Oracle

Choose the target before generating the script so identifier quoting and type inference match the destination more closely.

For MySQL-specific guidance, see CSV to MySQL INSERT Statements.

For PostgreSQL, see CSV to PostgreSQL INSERT Statements.

Review inferred column types

Excel does not provide a relational database schema.

A column that looks numeric may actually contain identifiers with leading zeros. A date column may contain text. A blank field may mean either NULL or an empty string.

Always review the generated CREATE TABLE statement.

For example, postal codes such as:

00123
00456

should usually remain text rather than becoming integers.

Handle apostrophes and text safely

Spreadsheet text can contain apostrophes:

O'Connor

In a SQL string literal, that must be escaped:

'O''Connor'

The converter handles generated value escaping.

Generate batched INSERT statements

Rather than creating one INSERT per spreadsheet row, the converter can group multiple rows:

INSERT INTO employees (id, name)
VALUES
  (1, 'Ada'),
  (2, 'Grace'),
  (3, 'Alan');

Batching makes generated scripts easier to run and review.

When a spreadsheet is too large

For very large worksheets, a generated SQL script may not be the best import method.

Database-native loaders such as PostgreSQL COPY or MySQL LOAD DATA are usually better for high-volume ingestion.

Use SQL generation when you value portability and reviewability more than raw import speed.

Excel column to IN clause

If you only need to turn one spreadsheet column into a filter rather than insert rows, use the SQL IN Clause Generator.

See How to Convert an Excel Column to a SQL IN Clause.

For a full spreadsheet-to-table workflow, open the CSV to SQL Converter.