RevealTheme logo

CSV sang SQL INSERT

Tạo các câu lệnh SQL INSERT từ dữ liệu CSV. Hữu ích để nhập các tệp xuất CSV vào cơ sở dữ liệu.

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

Cách sử dụng công cụ này

  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 sang SQL INSERT là gì?

Việc nhập hàng loạt CSV vào cơ sở dữ liệu thường đòi hỏi các câu lệnh INSERT. Bộ tạo này sinh ra các câu lệnh INSERT theo chuẩn SQL hoạt động trên MySQL, PostgreSQL, SQLite và hầu hết các hệ quản trị cơ sở dữ liệu khác. Đối với các tệp CSV rất lớn (hơn 10.000 dòng), nên dùng tiện ích gốc của cơ sở dữ liệu (LOAD DATA / COPY FROM): nó nhanh hơn nhiều bậc.

Các trường hợp sử dụng phổ biến

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

Câu hỏi thường gặp

Công cụ có xử lý các ký tự đặc biệt trong giá trị không?
Có: các dấu nháy đơn được thoát đúng cách.
Còn các giá trị NULL thì sao?
Các ô trống được chuyển thành chuỗi rỗng. Hãy thay thế chúng bằng NULL thủ công nếu cần.

Công cụ liên quan