RevealTheme logo

CSV轉SQL INSERT

根據CSV資料產生SQL INSERT語句。適用於將CSV匯出檔案匯入資料庫。

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

如何使用本工具

  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.

什麼是CSV轉SQL INSERT?

將CSV批次匯入資料庫通常需要用到INSERT語句。本產生器會產生標準SQL的INSERT語句,可在MySQL、PostgreSQL、SQLite以及大多數其他資料庫管理系統中執行。對於非常大的CSV(超過10000列),更推薦使用資料庫自帶的工具(LOAD DATA / COPY FROM):它的速度要快上好幾個數量級。

常見使用場景

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

常見問題

它能處理值中的特殊字元嗎?
可以:單引號會被正確跳脫。
那NULL值呢?
空儲存格會被轉換為空字串。如有需要,請手動將其替換為NULL。

相關工具