CodeEraFree roadmap

SQL Practice / INSERT command

SQL INSERT INTO: practice questions with answers

3 questions with solved queries and real output. Outputs checked on MariaDB 10.11 (MySQL-compatible) on 23 November 2026.

INSERT INTO adds new rows to a table. You can give values for every column in order, or name only the columns you want to fill. Columns you leave out get their default value, which is NULL unless the table says otherwise. To add many rows in one go, put several value lists in the same statement, separated by commas.

INSERT INTO table_name VALUES (v1, v2, ...);

INSERT INTO table_name (col1, col2) VALUES (v1, v2), (v3, v4);
Table you need first
CREATE TABLE orderDetail (
  id           INT PRIMARY KEY,
  product_name VARCHAR(50) NOT NULL,
  order_date   DATE,
  price        DECIMAL(10,2) NOT NULL,
  quantity     INT
);

Run this once. If you did the previous set, you already have it.

Do these in order. Each question uses what the one before it created or changed.

How to use this page: read a question, write your own query, then open "Show the answer" and compare. Trying first is what makes it stick.

Question 1Insert one record in the "orderDetail" table. Sample data: id 1, product_name Pen, order_date 2023-01-01, price 9.05, quantity 3.

Show the answer and the output
INSERT INTO orderDetail VALUES (1, 'Pen', '2023-01-01', 9.05, 3);

Output

Query OK, 1 row affected.

Then check with SELECT * FROM orderDetail ORDER BY id

idproduct_nameorder_datepricequantity
1Pen2023-01-019.053

Question 2Insert at least 5 records at once in the "orderDetail" table (your choice of data).

Show the answer and the output
INSERT INTO orderDetail VALUES
  (2, 'Book',   '2023-01-01', 520,   2),
  (3, 'Ink',    '2023-01-12', 50.55, 1),
  (4, 'Map',    '2023-01-19', 25,    5),
  (5, 'Bottle', '2023-01-30', 600,   1),
  (6, 'Marker', '2023-02-05', 80,    4);

Output

Query OK, 5 rows affected.

Then check with SELECT * FROM orderDetail ORDER BY id

idproduct_nameorder_datepricequantity
1Pen2023-01-019.053
2Book2023-01-01520.002
3Ink2023-01-1250.551
4Map2023-01-1925.005
5Bottle2023-01-30600.001
6Marker2023-02-0580.004

Question 3Insert 2 records only into the id, product_name and price columns.

Show the answer and the output
INSERT INTO orderDetail (id, product_name, price) VALUES
  (7, 'Pen',  65.90),
  (8, 'Tape', 10);

Output

Query OK, 2 rows affected.

Then check with SELECT * FROM orderDetail ORDER BY id

idproduct_nameorder_datepricequantity
1Pen2023-01-019.053
2Book2023-01-01520.002
3Ink2023-01-1250.551
4Map2023-01-1925.005
5Bottle2023-01-30600.001
6Marker2023-02-0580.004
7PenNULL65.90NULL
8TapeNULL10.00NULL

order_date and quantity were not listed, so they are stored as NULL. This only works because those columns allow NULL.

Want these as PDFs? Download the question PDF or the answer PDF to practise offline.