SQL INSERT
Add rows to a table.
Syntax
INSERT INTO t (col1, col2) VALUES (v1, v2), (v3, v4); INSERT INTO t (…) SELECT …;
List the columns; left-out columns get their DEFAULT or NULL.
Example
Query (on the shop database used in the SQL course)
INSERT INTO products (name, category, price) VALUES ('Webcam', 'Electronics', 89.0); SELECT product_id, name, price FROM products ORDER BY product_id DESC LIMIT 2;
Result
| product_id | name | price |
|---|---|---|
| 16 | Webcam | 89.0 |
| 15 | Gel pens, pack of 10 | 11.0 |
2 rows
Related
Learn it step by step in the free lesson Changing Data, with exercises that check your queries.