books with columns id, title, and priceid = 2 to 15 (with WHERE)books with columns id, title, and priceid = 2 to 15 (with WHERE)books with columns id (integer), title (text), and price (integer). Then insert these three rows exactly: (1, 'Learn SQL', 10), (2, 'Mastering Databases', 12), and (3, 'Data Science Basics', 15).Use CREATE TABLE to define the table and INSERT INTO with multiple rows to add data.
UPDATE query that sets the price of all books in the books table to 20. Do NOT use a WHERE clause.Use UPDATE books SET price = 20; without a WHERE clause to update all rows.
UPDATE query that sets the price of the book with id = 2 in the books table to 15. Use a WHERE clause to update only that book.Use WHERE id = 2 to update only the book with that id.
UPDATE without a WHERE clause can be dangerous.Use a SQL comment starting with -- to explain the risk.
What happens if you run an UPDATE statement without a WHERE clause?
WHERE clause limits which rows are updated. Without it, no filter is applied.WHERE, the update affects every row in the table.Which of the following is the correct syntax to update the salary column to 5000 for all employees in the employees table?
UPDATE employees SET salary = 5000;
UPDATE table_name SET column = value; to update all rows.Given the table products with 3 rows:
id | name | price ---+---------+------- 1 | Pen | 10 2 | Pencil | 5 3 | Eraser | 3
What will be the result after running this query?
UPDATE products SET price = price + 2;
WHERE clause, the update applies to all rows in the table.Consider this query intended to update only employees in department 10:
UPDATE employees SET salary = salary + 1000;
Why might this be a problem?
WHERE clause to filter employees by department.You want to increase the stock by 10 only for products with stock less than 5. Which query correctly avoids the danger of updating all rows?
stock < 5, so a WHERE clause is needed.UPDATE products SET stock = stock + 10 WHERE stock < 5; uses correct syntax and condition to update only matching rows. UPDATE products SET stock = stock + 10; (no WHERE) updates all rows. UPDATE products stock = stock + 10 WHERE stock < 5; (missing SET) has syntax error. UPDATE products SET stock = stock + 10 WHERE stock > 5; updates wrong rows (opposite condition).Pass the test and this pattern moves unknown