Skip to content

CSV to SQL converter

Paste CSV, or cells copied from Excel or Google Sheets, and get a CREATE TABLE statement and INSERT statements for your database. Everything runs in your browser.

SQL output

How to convert CSV to SQL

  1. Paste a CSV file, or copy a range of cells from Excel or Google Sheets with its header row, into the input panel.
  2. Pick the dialect of the database you're loading into and type the table name. Outside SQLite, a schema-qualified name such as staging.employees works too.
  3. Check the inferred column types in the CREATE TABLE statement, or turn it off if the table already exists.
  4. Copy the SQL or download it as a .sql file and run it against your database.

For example, a row with an apostrophe in a name and an empty email cell becomes:

INSERT INTO employees (employee_id, first_name, last_name, email)
VALUES (1003, 'Liam', 'O''Brien', NULL);

How column types are inferred

CSV has no types, so the converter reads every value in a column and picks the narrowest type that fits all of them. Whole numbers become INTEGER or BIGINT, decimals become NUMERIC (or DECIMAL with a precision and scale that fit the data), true and false become booleans, and ISO dates and date-times become date and timestamp columns. A single value that doesn't fit, such as N/A in a number column, makes the whole column text, so the INSERT statements always run.

Numbers with leading zeros, such as ZIP codes and product codes, stay text. Values are quoted for text, date, and timestamp columns and written bare for numbers, so the output loads without casts.

When to convert CSV to SQL

  • Loading a spreadsheet or CSV export into PostgreSQL, MySQL, SQLite, or SQL Server
  • Writing seed data or fixtures for a migration or test database
  • Moving a lookup table, such as country codes or price lists, into a database
  • Sharing a dataset as a single SQL script that recreates the table
  • Loading a one-off export from a SaaS tool so you can query it with SQL

Loading very large files

INSERT statements are the most portable way to load data, but for files with hundreds of thousands of rows a bulk loader is faster: COPY in PostgreSQL, LOAD DATA INFILE in MySQL, .import in the SQLite shell, and BULK INSERT in SQL Server. You can still use this converter to generate the CREATE TABLE statement for the target table.

From spreadsheets to answers

Once your data is in a database, Basedash lets you ask questions about it in plain English. It writes the SQL, runs it, and returns a chart or dashboard, and it connects to PostgreSQL, MySQL, BigQuery, Snowflake, and 750+ other data sources.

FAQ

How do I convert a CSV file to SQL INSERT statements?

Paste the CSV into the input panel, or open the file in a text editor and copy its contents. Choose your database dialect and type a table name. The converter writes a CREATE TABLE statement followed by INSERT statements as you type, using the first row as column names. Copy the SQL or download it as a .sql file, then run it in psql, the MySQL client, SQLite, or SQL Server Management Studio.

Can I convert an Excel or Google Sheets table to SQL?

Yes. Select the cells in Excel or Google Sheets, including the header row, copy them, and paste them into the input panel. Spreadsheets copy cells as tab-separated text, and the delimiter auto-detection reads tabs the same way as commas. You can also export the sheet as CSV first. Formulas are not carried over; the converter sees the values the cells display when you copy them.

How does the converter choose column types for CREATE TABLE?

It checks every non-empty value in a column. If all of them are whole numbers, the column becomes INTEGER, or BIGINT when a value is outside the 32-bit range. Numbers with decimals become NUMERIC or DECIMAL, true and false become BOOLEAN (BIT in SQL Server), YYYY-MM-DD values become DATE, and date-time values become a timestamp type. SQLite has no boolean or date types, so it gets INTEGER and TEXT. Anything else is text. Numbers with leading zeros, such as ZIP codes, stay text so the zeros aren't lost.

Which SQL dialects are supported, and what changes between them?

PostgreSQL, MySQL, SQLite, and SQL Server. The dialect changes identifier quoting (double quotes, backticks, or square brackets), the column types, and how values are written. For example, booleans are TRUE and FALSE in PostgreSQL and MySQL but 1 and 0 in SQLite and SQL Server, MySQL text columns become VARCHAR(255) or TEXT, and SQL Server statements are capped at 1,000 rows per INSERT, which is the limit for a VALUES list.

How are empty cells, quotes, and special characters handled?

Empty cells become NULL. Single quotes inside values are doubled, so O'Brien is written as 'O''Brien', and MySQL output also escapes backslashes. Quoted CSV fields can contain commas and line breaks, following RFC 4180. Column names that contain spaces, capitals, or reserved words are quoted for the chosen dialect, or you can turn on snake_case names to get first_name instead of "First name".

Is my CSV uploaded to a server?

No. Parsing and SQL generation run entirely in your browser with JavaScript, so customer lists, exports, and other sensitive files never leave your machine. Nothing is logged or stored. Files of a few megabytes convert comfortably; for very large files, a bulk loader such as PostgreSQL COPY or MySQL LOAD DATA is faster than INSERT statements.

Skip the import and ask your data

Connect your data and describe what you want to see. Basedash handles the query, visualization, and dashboard.