SQL INSERT is a core Data Manipulation Language (DML) command that appends data to an existing table or updatable view. It can insert a single row, multiple rows, or the result set of a subquery. INSERT can work with explicit column lists, default values, or expressions. Some dialects extend INSERT with clauses like RETURNING (PostgreSQL), ON CONFLICT/ON DUPLICATE KEY (PostgreSQL, SQLite, MySQL), or OUTPUT (SQL Server) to make row-level feedback or upsert behavior possible. Because INSERT permanently changes data, it should be wrapped in a transaction when atomicity or rollback capability is required. Attempting to insert data that violates constraints (primary key, uniqueness, foreign key, NOT NULL, or check constraints) will raise an error unless conflict-handling syntax is used.
table_name
(identifier) - Target table or updatable view.column_list
(identifier) - Optional comma-separated list of target columns.VALUES
(keyword) - Introduces literal value tuples to insert.value_list
(expression) - One or more comma-separated expressions per row.subquery
(query) - SELECT statement supplying rows for insertion.DEFAULT
(keyword) - Inserts default column value defined in schema.RETURNING
(clause) - Optional dialect clause that returns inserted rows.ON CONFLICT
(clause) - Optional dialect clause for upsert/ignore logic.SQL UPDATE, SQL DELETE, SQL MERGE, SQL SELECT, UPSERT, ON CONFLICT, ON DUPLICATE KEY, RETURNING clause, TRANSACTION
ANSI SQL-86
INSERT only adds new rows. UPSERT (INSERT ... ON CONFLICT/ON DUPLICATE KEY) inserts or updates depending on whether a conflict occurs.
Omit the column in the column list or explicitly use DEFAULT in the VALUES list or the DEFAULT VALUES clause, if supported.
Large batches without indexing, unnecessary triggers, or row-by-row commits can degrade performance. Use bulk inserts inside a single transaction and disable indexes if possible.
Yes, but only if the view is updatable and you have the required permissions. Some databases restrict inserts when the view contains joins, aggregates, or DISTINCT.