On this page

How do I load a CSV file prepared in Excel into a table, with a preview first?

Applies to BroadSQL 5.5.0 · reviewed October 18, 2026

What you'll accomplish

Someone prepares rows in a spreadsheet and asks you to put them in a table: new reference values, a list of planned operations, corrections. Inserting them by hand is slow, and loading a file blindly risks a half-loaded table or values in the wrong columns.

You will save the sheet as a CSV file, check it against the target table with a preview that writes nothing, then insert every row in one transaction. The preview tells you, before anything changes, which columns match, how many rows are valid and which values would be rejected.

Short answer

Save the sheet as UTF-8 CSV with a header row, run LOAD <table> <file> PREVIEW;, then the same command without PREVIEW to insert after a confirmation.

Before you start

LOAD inserts into an existing table, so the example creates a small practice table of its own in WORLD: MY_VISIT, a list of planned visits to cities of the CITY table. Creating it changes the sample database, and Clean up removes it. (If you made WORLD the production connection of the practice set, run the example on WORLD-QA instead, or BroadSQL asks for a confirmation before each change.) Connected to WORLD:

Type at the BroadSQL prompt
CREATE TABLE MY_VISIT (CITY_ID INTEGER NOT NULL, VISIT_DATE DATE NOT NULL, NOTE VARCHAR(100));

Example

In Excel, prepare three rows under the headers CITY_ID, VISIT_DATE and NOTE (2974 is Paris, 3068 Berlin and 1464 Roma in CITY), then save the sheet as "CSV UTF-8" under the name my_visits.csv in the export folder (the DefaultFolder setting, c:\temp\ by default on Windows). Opened in a text editor, the file looks like this:

Content of the file my_visits.csv
CITY_ID;VISIT_DATE;NOTE
2974;2026-11-03;Kick-off meeting
3068;2026-11-17;"Workshop; day 1"
1464;2026-12-01;NULL

The separator is a semicolon, the CsvSeparator setting; the quotes keep the ; of Workshop; day 1 inside one value, and the word NULL stands for no value. Now check the file against the table, without writing:

Type at the BroadSQL prompt
LOAD MY_VISIT my_visits.csv PREVIEW;

The preview names the target, the file and the counts, then how each header matches a column:

BroadSQL session: after each prompt, what you type; the other lines are what BroadSQL prints
WORLD> LOAD MY_VISIT my_visits.csv PREVIEW;
LOAD PREVIEW
------------------------------------------------------------
Target      : WORLD / PUBLIC.MY_VISIT
Mode        : INSERT
Source      : c:\temp\my_visits.csv
Input rows  : 3
Valid rows  : 3
Rejected    : 0

Columns:
CITY_ID -> CITY_ID  INTEGER
VISIT_DATE -> VISIT_DATE  DATE
NOTE -> NOTE  VARCHAR

No changes have been made.
Illustrative output: the values come from the WORLD sample database and the layout from this release; it was not captured from a BroadSQL run, and your timings will differ.

Nothing was rejected, so insert the rows. Without PREVIEW, LOAD reads and checks the file again, then asks Load N rows into TABLE? [y/N]; answer y:

Type at the BroadSQL prompt
LOAD MY_VISIT my_visits.csv;

BroadSQL inserts the three rows and commits once, at the end:

What BroadSQL prints
3 row(s) inserted into PUBLIC.MY_VISIT (source rows read: 3, committed).

The visits can now be joined with the sample's own data:

Type at the BroadSQL prompt
SELECT V.VISIT_DATE, TRIM(C.NAME) AS CITY, C.COUNTRYCODE, V.NOTE
  FROM MY_VISIT V JOIN CITY C ON C.ID = V.CITY_ID ORDER BY V.VISIT_DATE;

When the preview rejects rows

Change 2026-11-17 into 17 November in the file and run the preview again: Valid rows drops to 2, Rejected becomes 1, and a line names the row, the column, the value and the reason. One rejected row prevents the whole load, so correct the file and preview again until nothing is rejected.

Variations

  • Without the question: LOAD MY_VISIT my_visits.csv EXECUTE; authorizes the insert explicitly. In a Script, plain LOAD refuses to write, so use PREVIEW or EXECUTE there.
  • Another folder: give a path, LOAD MY_VISIT c:\data\my_visits.csv PREVIEW;.
  • A comma separated file: set CsvSeparator=COMMA in BroadSQL.ini; the default is SEMICOLON.

Watch out

  • LOAD inserts only: it never updates existing rows. Loading the same file again inserts the same rows again; there is no automatic deduplication.
  • Columns are matched by header name, not position. An unknown header refuses the whole load.
  • The preview checks types, not constraints: a duplicate key is reported by the database when the rows are inserted, and the import is rolled back.
  • Finish other pending work first: LOAD commits or rolls back the connection's transaction.

Clean up

Remove the practice table when you no longer need it:

Type at the BroadSQL prompt
DROP TABLE MY_VISIT;

Commands used

Found something wrong or unclear on this page? , with the page address.