You can turn a spreadsheet of rows into ready-to-paste SQL INSERT statements without installing anything: use an online SQL generator, or build the statements in a blank column with a formula and save the file as CSV. Both routes give you text you can paste into your database client. The catch is that Excel adds noise - stray quotes, dates reformatted as numbers, apostrophes in names - so the cleaning steps below matter as much as the conversion itself. Before you start, make a copy of the workbook and read through the data type checklist so nothing is lost when the file is imported.

What You'll Need

  • A spreadsheet with one row per record and a header row naming each column exactly as your database column is named (or a mapping you are happy to write).
  • Access to an online SQL generator page or a browser-based spreadsheet tool that can export CSV. These are web pages, so they work on Windows, macOS, Linux and Chromebooks alike.
  • Your CREATE TABLE statement or a screenshot of the table structure, so you know which columns are numbers, which are text and which are dates.
  • A database client for testing the statements (phpMyAdmin, pgAdmin, DBeaver, MySQL Workbench, SSMS or a similar tool).
  • The table is empty or you have a way to roll back, because a badly formed batch can insert hundreds of junk rows in one go.

Step-by-Step

  1. Make a working copy. Save the file under a new name such as import-data.xlsx. Keep the original untouched so you can restart if the headers need reordering. Menu names vary slightly by Excel version and by desktop versus Excel for the web, but the steps below are for the desktop app; the online version has the same commands under slightly different ribbon labels.
  2. Name your headers after your columns. Rename each header cell so it matches the column name in the database exactly - first_name, not First Name. Avoid spaces and capital letters unless the database column really uses them. If your table uses capitalised quoted identifiers, keep the capitals, but be aware that unquoted names in most databases are case-insensitive and get folded to lower case.
  3. Copy the headers into a plain text note. You will paste this list into the generator or into your formula, and it is also the list you check against the CREATE TABLE statement. A single typo in a column name is the most common reason a batch fails.
  4. Delete blank rows and blank columns. Empty trailing rows and columns confuse generators, which may produce INSERT statements with the wrong number of values. Highlight the data, press Ctrl+End (or Cmd+End on a Mac) to see where the used range really ends and delete anything beyond it.
  5. Fix the apostrophes. In SQL, a single quote marks the start and end of a text value. A name like O'Brien ends the string early and breaks the statement. For a formula-based build you double the quote; for a generator, check that it has an option to escape single quotes and turn it on. Alternatively, clean the data in the sheet: use Find and Replace to swap ' for '' in text columns only, never in numeric columns.
  6. Normalise the dates. SQL expects YYYY-MM-DD for date columns, while Excel stores dates as serial numbers and displays them in your regional format. Add a helper column with =TEXT(A2,"YYYY-MM-DD") to produce a clean string, or format the column as text before typing or importing. Do this deliberately rather than trusting the export.
  7. Check numbers and decimals. Remove thousands separators, currency symbols and text-only leading zeros you did not mean to keep. Decide per column whether it is an integer, a decimal, or a zero-padded code that must stay as text. A telephone number column must be text, or you will lose the leading zero and the number will be stored in scientific notation.
  8. Choose your conversion route. If you have a few dozen rows, paste them into an online SQL INSERT generator page: most accept pasted cells or a CSV upload, let you pick the target table and the quote character, and output the full INSERT INTO batch. If your data is large or sensitive, do not upload it - use the formula route instead so the data never leaves your machine.
  9. Build the statements with a formula instead. In a new column on the first data row, write a formula that concatenates the table name, the column list and the quoted values, for example ="INSERT INTO customers (first_name,last_name,email) VALUES ('"&A2&"','"&B2&"','"&C2&"');". Fill it down. Every text value needs the surrounding quote marks; every number and date should not have them if the column type is numeric or date. Wrap the whole formula in a double click on the fill handle to copy it down to the last row.
  10. Copy the formula column as values. Select the column, copy it, then paste special as values into a fresh column so the formulas do not tag along. This avoids pasting live formulas into your SQL editor.
  11. Move to plain text before quitting Excel. Save as CSV (comma delimited) or paste the column into a plain text editor like Notepad, TextEdit, or VS Code. Excel's copy buffer can carry formatting; plain text strips it. If you save as CSV, note that a quote-heavy SQL string is fine as long as you only paste the column and do not re-open the CSV, which would re-interpret the quotes.
  12. Test with one row. Paste a single INSERT into your client and run it. Check that the row appears with the right values in the right columns, that dates are dates and prices have the right number of decimals. Only then run the rest. Wrap the batch in a transaction with BEGIN; and COMMIT; where your database supports it, so a failure halfway leaves nothing behind; if you are not sure, run in small batches.
  13. Verify row counts. Compare the number of rows in your sheet with the number of rows inserted. A mismatch usually means a blank row was skipped, a line break inside a cell split a statement across two lines, or the final row was missing a semicolon.

Common Mistakes

The most frequent failure is mismatched column order: the header list says one thing and the values are in a different order. Because INSERT ... VALUES depends on position, you can silently write email addresses into phone columns. Count the values against the column list before you run anything.

Second is quoting. Text values must be wrapped in single quotes; numbers must not be. Generators that add quotes to every value will store 42 as a string, which fails on strict integer columns and breaks sorting and maths later. Third is line breaks and commas inside cells: an address with a comma is fine inside quotes, but a stray newline can split one statement into two and cascade errors through the batch. Fourth, people forget the semicolon at the end of each statement. Fifth, they paste into a client set to the wrong database or schema and insert into a different table of the same name.

Tips

  • Add a small formula to spot unbalanced quotes: count the quote characters in a cell and check the total is even before it goes into the string.
  • Use a header row that is identical to the INSERT column list, then copy that list once rather than retyping it for every batch.
  • Generate and run the batch for 10 rows first as a smoke test. If those are right, the other 9,000 almost certainly are.
  • For very large sheets, split the output into chunks of a few hundred statements per batch; statements that are too long can hit limits in some clients or hosts.
  • Keep the formula in a separate column and hide it, so the sheet still reads cleanly for anyone else who opens it.
  • If the data is personal, avoid uploading it to a random generator page. The formula route keeps it on your machine.

Troubleshooting

If the first test row fails, read the error rather than the guess. "Unknown column" means the header does not match the table - compare against the actual table structure. "Column count doesn't match value count" means a value is missing or an extra comma slipped in, including a trailing comma after the last value. A syntax error near a word usually means an unescaped apostrophe closed a string early.

If numbers arrive as strings, remove quotes from numeric values or the generator has quoted everything; set the type per column. If dates arrive as 45000 or similar, Excel exported the serial number - add the TEXT helper column. If accents turn into odd characters, save the file as UTF-8 and check your client's encoding, usually a charset setting on the connection. If nothing inserts and there is no error, the client may be in autocommit off mode without a COMMIT, so the transaction is open and invisible to other sessions. Finally, if the batch half-run leaves junk, delete the inserted rows by the range or roll back before retrying; a restore that wipes data should only be done after taking a backup.

Frequently Asked Questions

Can I do this with no coding at all?

Yes - that is exactly what an online INSERT generator does. You paste your cells or upload a CSV, pick the table name, and it writes the SQL. The formula approach needs only basic spreadsheet skills and no programming, though the formula itself is written like code.

Is it safe to paste my spreadsheet into an online tool?

Only for data you are comfortable sharing. Many pages process data in the browser without uploading, but not all do, and you cannot always tell. For customer names, emails or anything personal, use the formula and CSV route so the data stays local.

Why does my INSERT fail on names with apostrophes?

Because the single quote ends the string early. Double every apostrophe inside text values, or enable the generator's escape option. Replace in text columns only - never in number columns, where the quote would be stored as part of the value.

Should I paste the CSV text or the Excel sheet directly?

Paste plain text. Copying from Excel can carry tabs and formatting that some clients interpret as delimiters. Copy the formula column into Notepad or a similar plain text editor and paste from there. If you exported CSV, paste the column text, not the file into the SQL editor.

How many rows can I insert at once?

That depends on your client and server, not on Excel. A few hundred rows per batch is a safe habit; if a big batch times out, split it. Many clients allow a multi-row INSERT with several value groups in one statement, which is faster but harder to debug when one value is wrong.