The INSERT statement is one of the four fundamental SQL operations (SELECT, INSERT, UPDATE, DELETE). It adds one or more rows to a table. Despite being simple in concept, there are several ways to write INSERT statements incorrectly — and the errors aren't always obvious.
Basic Syntax
The basic INSERT statement specifies the table, the columns receiving values, and the values themselves:
INSERT INTO customers (name, email, plan) VALUES ('Alice Morrison', 'alice@example.com', 'pro');
The column list and values list must match in count and order. If you omit the column list, you must provide values for every column in the table in their definition order — which is fragile if the table schema changes.
Batch INSERT: Multiple Rows in One Statement
For efficiency, you can insert multiple rows in a single INSERT statement by separating value groups with commas:
Upload your CSV and see exactly what's wrong — Sohovi profiles quality in seconds — try Sohovi free.
INSERT INTO customers (name, email, plan) VALUES ('Alice Morrison', 'alice@example.com', 'pro'), ('Bob Chen', 'bob@example.com', 'free'), ('Carol Diaz', 'carol@example.com', 'enterprise');
This is dramatically more efficient than separate single-row inserts because it reduces the number of round trips between the application and the database. For loading data from a CSV, batch inserts of 500-1000 rows per statement are typical.
Handling NULL Values
Empty cells in a source CSV should become NULL in SQL, not an empty string. The difference matters:
- NULL means "no value" — it's excluded from COUNT(), doesn't match equality conditions, and is handled specially by most database functions
- An empty string '' is a value — it matches WHERE email = '', is included in COUNT(), and has different semantics
When generating INSERT statements from CSV, make sure empty cells produce NULL (without quotes) rather than '' (empty string in quotes).
The Apostrophe Problem
Text values in SQL are enclosed in single quotes. If the text itself contains a single quote — like an Irish surname such as O'Brien — the apostrophe will prematurely end the string and cause a syntax error (or worse, a SQL injection vulnerability if the value came from user input).
The fix is to escape apostrophes by doubling them: O''Brien. Good CSV to SQL generators do this automatically. Verify that yours does before running generated SQL against a production database.
Column Types and Type Coercion
Inserting a text value into an INTEGER column will either fail with a type error or silently coerce the value, depending on the database. PostgreSQL is strict and will raise an error. SQLite is permissive and will attempt coercion. MySQL is somewhere in between.
Review the CREATE TABLE statement's column types against your source data before running any bulk INSERT. If a column is defined as DATE, ensure all values conform to the expected date format.
Sohovi's free CSV to SQL generator handles NULL values, apostrophe escaping, and multi-row batch inserts in MySQL, PostgreSQL, SQLite, and MSSQL syntax.
Sohovi profiles every column in your dataset for completeness and flags the exact rows where values are missing — free to try.
Keep Reading
Generate SQL INSERT Statements from CSV Free →