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。

相关工具