RevealTheme logo

CSV para SQL INSERT

Gera instruções SQL INSERT a partir de dados CSV. Útil para importar exportações CSV para bancos de dados.

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

Como usar esta ferramenta

  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.

O que é CSV para SQL INSERT?

Importar CSV em massa para um banco de dados normalmente exige instruções INSERT. Este gerador produz INSERT em SQL padrão que funcionam no MySQL, PostgreSQL, SQLite e na maioria dos demais SGBDs. Para CSVs muito grandes (mais de 10.000 linhas), é preferível usar o utilitário nativo do seu banco de dados (LOAD DATA / COPY FROM): ele é ordens de magnitude mais rápido.

Casos de uso comuns

  • 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.

Perguntas frequentes

Ele trata os caracteres especiais nos valores?
Sim: as aspas simples são escapadas corretamente.
E os valores NULL?
As células vazias se tornam strings vazias. Substitua-as por NULL manualmente, se necessário.

Ferramentas relacionadas