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

Show:
Database System Support Status Since Version Notes
MySQL ✓ Supported all Standard
PostgreSQL ✓ Supported all Standard
SQL Server ✓ Supported all Standard + OUTPUT
Oracle ✓ Supported all Standard + RETURNING
SQLite ✓ Supported all Standard

Details

Basic DML for creating rows.

Standard Syntax

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

Version Support

MySQL: Since all PostgreSQL: Since all SQL Server: Since all Oracle: Since all SQLite: Since all

Per-Database Syntax & Notes

MySQL

Standard

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

PostgreSQL

Standard

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

SQL Server

Standard + OUTPUT

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

Oracle

Standard + RETURNING

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

SQLite

Standard

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