RevealTheme logo

Da CSV a SQL INSERT

Genera istruzioni SQL INSERT a partire da dati CSV. Utile per importare esportazioni CSV nei database.

INSERT INTO my_table (name, value) VALUES ('A', '1');
INSERT INTO my_table (name, value) VALUES ('B', '2');

Come usare questo strumento

  1. 1

    Type the destination table name into the top field (it is dropped into the generated INSERT exactly as typed).

  2. 2

    Paste your CSV into the text box, keeping the header row first so its names become the column list.

  3. 3

    Read the INSERT statements that appear below as you type, with one statement per data row.

  4. 4

    Select the generated SQL and copy it into your database client or migration script to run it.

Che cos'è la conversione da CSV a SQL INSERT?

L'importazione massiva di file CSV in un database richiede solitamente istruzioni INSERT. Questo generatore produce istruzioni INSERT in SQL standard che funzionano in MySQL, PostgreSQL, SQLite e nella maggior parte degli altri DBMS. Per file CSV molto grandi (oltre 10.000 righe), è preferibile l'utilità nativa del suo database (LOAD DATA / COPY FROM): è più veloce di diversi ordini di grandezza.

Casi d'uso comuni

  • Seeding a few rows of test or fixture data into a local development database without writing the INSERTs by hand.

  • Converting a small spreadsheet export of lookup values (statuses, categories, country codes) into a migration script.

  • Drafting INSERT statements for a quick demo or tutorial where the data is short and contains no commas inside fields.

  • Reshaping a handful of rows copied from a CSV file into SQL you can paste into a query console.

  • Generating a starting point for a data-load script that you will then hand-edit to add NULLs or fix column types.

  • Teaching or learning SQL INSERT syntax by watching how column lists and quoted values are assembled from rows.

Domande frequenti

Gestisce i caratteri speciali nei valori?
Sì: gli apici singoli vengono sottoposti a escape correttamente.
E i valori NULL?
Le celle vuote vengono convertite in stringhe vuote. Le sostituisca manualmente con NULL se necessario.

Strumenti correlati