Skip to main content
Data Engineering & Conversion

SQL INSERT Statements Explained: Syntax, Examples, and Common Mistakes

INSERT INTO is how you add rows to a SQL database. Here's the syntax, how batch inserts work, how to handle NULLs, and the mistakes that cause errors.

Key Takeaways
  • Always specify the column list in INSERT — don't rely on positional order, which breaks if the schema changes.
  • Batch inserts (multiple value groups per statement) are far more efficient than single-row inserts for bulk loading.
  • Empty cells should become NULL, not empty string — the two have different behaviour in SQL queries.
  • Apostrophes in text values must be escaped by doubling them — O'Brien becomes O''Brien.

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.

Frequently Asked Questions

What is a SQL INSERT statement?

INSERT INTO adds one or more rows to a database table. The syntax specifies the table name, a list of column names, and a list of values in matching order. Multiple rows can be inserted in one statement by separating value groups with commas.

How do I insert multiple rows in SQL?

Add multiple value groups separated by commas after the VALUES keyword: INSERT INTO t (a, b) VALUES (1, 'x'), (2, 'y'), (3, 'z'). This inserts three rows in one statement, which is more efficient than three separate INSERT statements.

How do I handle NULL values in a SQL INSERT?

Write NULL (without quotes) in the values list where a field should be empty. Don't use an empty string '' unless the column is defined as text and you genuinely want an empty string. NULL and empty string behave differently in WHERE clauses, aggregations, and JOIN conditions.

Selva Santosh

Data quality, for people who ship

Selva writes practical guides on data quality, profiling, and governance to help teams ship better data.

Start for free

Stop guessing. Start knowing your data quality.

Sohovi profiles your datasets in minutes — surfacing completeness gaps, type mismatches, and duplicate patterns before they reach production.

No credit card required · Free forever plan