INSERT INTO is a Data Manipulation Language (DML) statement used to populate tables with data. It can insert a single row, multiple literal rows, or the result set of a subquery. Most dialects also support DEFAULT values, expressions, and optional RETURNING clauses to fetch generated columns (such as serial IDs). When a column list is omitted, values must be supplied for every column in the table in declared order. Failing constraints (NOT NULL, UNIQUE, CHECK, foreign keys) causes the statement to error or, in some dialects, be silently ignored when paired with modifiers like INSERT IGNORE. Some databases support advanced variants such as INSERT ... ON CONFLICT/ON DUPLICATE KEY or INSERT ALL, but the core INSERT INTO syntax remains ANSI-SQL compliant. The operation is transactional: if an INSERT appears inside an open transaction block, changes become permanent only after COMMIT and can be undone with ROLLBACK.
table_name
(identifier) - Destination table or updatable view.column_list
(list) - Optional. Explicit columns receiving data.VALUES
(keyword) - Introduces literal value tuples.value_tuple
(expression) - Comma-separated list of expressions per row.subquery
(query) - SELECT statement whose result rows are inserted.DEFAULT
(keyword) - Fills column with its default value.RETURNING
(clause) - Optional. Returns rows of generated data (dialect specific).INSERT ALL, INSERT OVERWRITE (Hive), UPSERT, MERGE, UPDATE, DELETE, ON CONFLICT, ON DUPLICATE KEY, RETURNING, TRANSACTION
SQL-86 (first ANSI SQL standard)
List only the columns you want to set and omit others. The database fills missing columns with their DEFAULT expressions or NULL if allowed.
Yes. Replace the VALUES clause with a SELECT statement that returns columns compatible with the target column list.
Use RETURNING (PostgreSQL, Oracle, SQLite) or OUTPUT (SQL Server). In MySQL call LAST_INSERT_ID() right after the insert.
Absolutely. Inside an explicit transaction, you can COMMIT to persist or ROLLBACK to undo the inserted rows.