Data changes

SQL INSERT

Add rows to a table.

Availability: Common SQL with references for SQL standard, MySQL/MariaDB, PostgreSQL, SQL Server, SQLite and Oracle Database; syntax and feature support vary by engine and version.中文

Syntax

INSERT INTO table_name (column_a, column_b) VALUES (value_a, value_b);

Examples

Example (standard-style syntax). Verify supported keywords in your database.

INSERT INTO users (name, email) VALUES ('Ada', 'ada@example.com');

SQLite-oriented variant; dialect behaviour may differ.

INSERT INTO users (name, email) VALUES ('Ada', 'ada@example.com');

Parameters, options and clauses

Option / clauseDescription
Column listName columns receiving values; omitted columns use defaults or NULL where permitted.
VALUESProvide one or more rows of values.
INSERT ... SELECTInsert rows returned by a query.
ON CONFLICT / ON DUPLICATE KEYHandle key conflicts using dialect-specific upsert syntax.
RETURNING / OUTPUTReturn inserted values where supported.

Dialect references

Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory