CodeEraFree roadmap

SQL Practice / UPDATE command

SQL UPDATE Command: practice questions with answers

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

UPDATE changes existing rows. SET says which columns get which new values, and WHERE picks the rows. If you leave out WHERE, every row is updated. Many real-world data accidents come from that missing line, so run the matching SELECT first when you are unsure.

Each question below starts from the original products table, so you can try them one at a time. After each query we show the whole table.

UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;
Set up the practice tables

Copy this script and run it once.

CREATE TABLE products (
  prod_id   CHAR(10) NOT NULL,
  prod_name CHAR(255) NOT NULL,
  price     DECIMAL(8,2) NOT NULL,
  quantity  INT,
  PRIMARY KEY (prod_id)
);

INSERT INTO products (prod_id, prod_name, price, quantity) VALUES
('BR01',   '8 inch teddy bear',   5.99,  8),
  ('BR02',   '12 inch teddy bear',  8.99,  12),
  ('BR03',   '18 inch teddy bear',  11.99, 18),
  ('BNBG01', 'Fish bean bag toy',   3.49,  7),
  ('BNBG02', 'Bird bean bag toy',   3.49,  20),
  ('BNBG03', 'Rabbit bean bag toy', 3.49,  9),
  ('RGAN01', 'Raggedy Ann',         4.99,  15),
  ('RYL01',  'King doll',           9.49,  12),
  ('RYL02',  'Queen doll',          9.49,  26);

Table: products

prod_idprod_namepricequantity
BNBG01Fish bean bag toy3.497
BNBG02Bird bean bag toy3.4920
BNBG03Rabbit bean bag toy3.499
BR018 inch teddy bear5.998
BR0212 inch teddy bear8.9912
BR0318 inch teddy bear11.9918
RGAN01Raggedy Ann4.9915
RYL01King doll9.4912
RYL02Queen doll9.4926

You can do these in any order. Each answer below was run on a fresh copy of the original table, so earlier queries do not change later results.

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 1Increase the price of all products by 10%.

Show the answer and the output
UPDATE products SET price = price * 1.1;

Output

Query OK, 9 rows affected.

Then check with SELECT * FROM products ORDER BY prod_id

prod_idprod_namepricequantity
BNBG01Fish bean bag toy3.847
BNBG02Bird bean bag toy3.8420
BNBG03Rabbit bean bag toy3.849
BR018 inch teddy bear6.598
BR0212 inch teddy bear9.8912
BR0318 inch teddy bear13.1918
RGAN01Raggedy Ann5.4915
RYL01King doll10.4412
RYL02Queen doll10.4426

Question 2Set the price of all products with a quantity less than 10 to 5.99.

Show the answer and the output
UPDATE products SET price = 5.99 WHERE quantity < 10;

Output

Query OK, 2 rows affected.

Then check with SELECT * FROM products ORDER BY prod_id

prod_idprod_namepricequantity
BNBG01Fish bean bag toy5.997
BNBG02Bird bean bag toy3.4920
BNBG03Rabbit bean bag toy5.999
BR018 inch teddy bear5.998
BR0212 inch teddy bear8.9912
BR0318 inch teddy bear11.9918
RGAN01Raggedy Ann4.9915
RYL01King doll9.4912
RYL02Queen doll9.4926

Question 3Double the price of products with a quantity between 15 and 50.

Show the answer and the output
UPDATE products SET price = price * 2 WHERE quantity BETWEEN 15 AND 50;

Output

Query OK, 4 rows affected.

Then check with SELECT * FROM products ORDER BY prod_id

prod_idprod_namepricequantity
BNBG01Fish bean bag toy3.497
BNBG02Bird bean bag toy6.9820
BNBG03Rabbit bean bag toy3.499
BR018 inch teddy bear5.998
BR0212 inch teddy bear8.9912
BR0318 inch teddy bear23.9818
RGAN01Raggedy Ann9.9815
RYL01King doll9.4912
RYL02Queen doll18.9826

Question 4Update the product name of the product with prod_id 'RGAN01' to 'Barbie Doll' and also update its price to 6.99.

Show the answer and the output
UPDATE products
SET prod_name = 'Barbie Doll', price = 6.99
WHERE prod_id = 'RGAN01';

Output

Query OK, 1 row affected.

Then check with SELECT * FROM products ORDER BY prod_id

prod_idprod_namepricequantity
BNBG01Fish bean bag toy3.497
BNBG02Bird bean bag toy3.4920
BNBG03Rabbit bean bag toy3.499
BR018 inch teddy bear5.998
BR0212 inch teddy bear8.9912
BR0318 inch teddy bear11.9918
RGAN01Barbie Doll6.9915
RYL01King doll9.4912
RYL02Queen doll9.4926

Question 5Increase the price by 5% for products with the word 'toy' in the name.

Show the answer and the output
UPDATE products SET price = price * 1.05 WHERE prod_name LIKE '%toy%';

Output

Query OK, 3 rows affected.

Then check with SELECT * FROM products ORDER BY prod_id

prod_idprod_namepricequantity
BNBG01Fish bean bag toy3.667
BNBG02Bird bean bag toy3.6620
BNBG03Rabbit bean bag toy3.669
BR018 inch teddy bear5.998
BR0212 inch teddy bear8.9912
BR0318 inch teddy bear11.9918
RGAN01Raggedy Ann4.9915
RYL01King doll9.4912
RYL02Queen doll9.4926

Question 6Add the prefix 'SALE: ' to the beginning of the product name for all products.

Show the answer and the output
UPDATE products SET prod_name = CONCAT('SALE: ', prod_name);

Output

Query OK, 9 rows affected.

Then check with SELECT * FROM products ORDER BY prod_id

prod_idprod_namepricequantity
BNBG01SALE: Fish bean bag toy3.497
BNBG02SALE: Bird bean bag toy3.4920
BNBG03SALE: Rabbit bean bag toy3.499
BR01SALE: 8 inch teddy bear5.998
BR02SALE: 12 inch teddy bear8.9912
BR03SALE: 18 inch teddy bear11.9918
RGAN01SALE: Raggedy Ann4.9915
RYL01SALE: King doll9.4912
RYL02SALE: Queen doll9.4926

Question 7Decrease the stock quantity by 1 for products with a quantity more than 10.

Show the answer and the output
UPDATE products SET quantity = quantity - 1 WHERE quantity > 10;

Output

Query OK, 6 rows affected.

Then check with SELECT * FROM products ORDER BY prod_id

prod_idprod_namepricequantity
BNBG01Fish bean bag toy3.497
BNBG02Bird bean bag toy3.4919
BNBG03Rabbit bean bag toy3.499
BR018 inch teddy bear5.998
BR0212 inch teddy bear8.9911
BR0318 inch teddy bear11.9917
RGAN01Raggedy Ann4.9914
RYL01King doll9.4911
RYL02Queen doll9.4925

Question 8Update the quantity to NULL for products with a price more than 9.

Show the answer and the output
UPDATE products SET quantity = NULL WHERE price > 9;

Output

Query OK, 3 rows affected.

Then check with SELECT * FROM products ORDER BY prod_id

prod_idprod_namepricequantity
BNBG01Fish bean bag toy3.497
BNBG02Bird bean bag toy3.4920
BNBG03Rabbit bean bag toy3.499
BR018 inch teddy bear5.998
BR0212 inch teddy bear8.9912
BR0318 inch teddy bear11.99NULL
RGAN01Raggedy Ann4.9915
RYL01King doll9.49NULL
RYL02Queen doll9.49NULL

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