Generate UPDATE Statements from Excel: Bulk Edit Database Rows

2026-07-01

When to use UPDATE instead of INSERT

Use UPDATE when rows already exist and you only need to change some columns:

  • Bulk email or phone updates
  • Fixing wrong order status or price after import
  • Refreshing config by business key
  • Rolling back a batch in a test database

ComTools Excel to SQL builds UPDATE scripts from Excel or CSV: pick SET columns (fields to change) and WHERE columns (row keys). Each spreadsheet row becomes one UPDATE statement.

Prepare your Excel file

Same rules as INSERT: row 1 is headers, data starts at row 2.

UPDATE example (keyed by UserId, updating Email and Age):

UserId Email Age
1001 new-alice@example.com 29
1002 new-bob@example.com 33

Important: A column used in SET must not also be marked as WHERE. Keep keys like UserId in WHERE only.

Steps (UPDATE)

  1. Open Excel to SQL.
  2. Upload .xlsx, .xlsm, or .csv; select the target sheet.
  3. Set statement type to Update.
  4. Enter the table name, e.g. dbo.Users.
  5. Choose database type (SQL Server, MySQL, PostgreSQL, etc.).
  6. In the column grid:
    • Include columns → SQL SET clause (Email, Age)
    • WHERE columns → match keys (UserId)
  7. Click Generate, then copy or download the SQL.

Sample output

UPDATE dbo.Users SET Email = 'new-alice@example.com', Age = 29 WHERE UserId = 1001;
UPDATE dbo.Users SET Email = 'new-bob@example.com', Age = 33 WHERE UserId = 1002;

With quote identifiers enabled, column names follow the selected SQL dialect (e.g. [Email] on SQL Server).

Common scenarios

Scenario SET columns WHERE columns
Change email by user ID Email UserId
Fix order status Status, UpdatedAt OrderId
Single field fix Target field Primary / business key
Composite key Fields to update Multiple WHERE columns (AND)

Safety checklist

A wrong WHERE clause can touch too many rows:

  1. Run on a test database first; verify affected rows.
  2. Run an equivalent SELECT before UPDATE (the tool also supports Select type for preview queries).
  3. Back up tables or the database before production changes.
  4. Execute large scripts in batches of 500–1000 statements.
  5. At least one WHERE column is required—the tool blocks accidental full-table updates.
-- verify before UPDATE
SELECT * FROM dbo.Users WHERE UserId IN (1001, 1002);

Temp table preview

If the table name starts with # (e.g. #Preview), the tool will:

  1. Emit CREATE TABLE
  2. Insert preview rows so you can compare with Excel
  3. Append SELECT and DROP at the end

Useful to validate spreadsheet data before applying UPDATE to a real table.

Work with INSERT and DELETE

Task Guide
New rows INSERT guide
Edit existing rows This UPDATE guide
Remove bad rows DELETE guide (coming soon)
Multiple source files MergeDedup → Excel to SQL

Excel to SQL series

FAQ

Can one column be both SET and WHERE?
No. Keys belong in WHERE only.

Composite primary keys?
Mark multiple WHERE columns; the tool generates WHERE A = ... AND B = ....

Excel to SQL vs Generate UPDATE developer tool?
Generate UPDATE suits small pasted JSON rows; the Excel path is better for full sheets and many columns.

Batch multiple UPDATEs into one statement?
Each row is one UPDATE for easier review and rollback; run in chunks for large jobs.


中文版