Add new rows to a table.

Adds new rows to a table, either as single rows or bulk inserts. Can insert literal values, results of SELECT queries, or DEFAULT to use column defaults. On conflict, use ON CONFLICT (PostgreSQL/MySQL) or MERGE to avoid errors.

Compatibility

Filter by Database
SQL INSERT Compatibility Across Databases
Database System Support Status Since Version Notes
MySQL Native all Standard
PostgreSQL Native all Standard
SQL Server Native all Standard + OUTPUT
Oracle Native all Standard + RETURNING
SQLite Native all Standard

Details

Basic DML for creating rows.

Standard Syntax

INSERT INTO table_name (col1, col2) VALUES (v1, v2);

Version Support

MySQL: Native in all listed versions PostgreSQL: Native in all listed versions SQL Server: Native in all listed versions Oracle: Native in all listed versions SQLite: Native in all listed versions

Per-Database Syntax & Notes

MySQL Native syntax

Standard

INSERT INTO tbl (c1,c2) VALUES (v1,v2);

PostgreSQL Native syntax

Standard

INSERT INTO tbl (c1,c2) VALUES (v1,v2) RETURNING id;

SQL Server Native syntax

Standard + OUTPUT

INSERT INTO tbl (c1,c2) OUTPUT inserted.id VALUES (v1,v2);

Oracle Native syntax

Standard + RETURNING

INSERT INTO tbl (c1,c2) VALUES (v1,v2) RETURNING id INTO :new_id;

SQLite Native syntax

Standard

INSERT INTO tbl (c1,c2) VALUES (v1,v2);