0
0
SQLquery~5 mins

UPDATE with WHERE condition in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the UPDATE statement do in SQL?
The UPDATE statement changes existing data in a table by modifying one or more columns for rows that match a condition.
Click to reveal answer
beginner
Why is the WHERE clause important in an UPDATE statement?
The WHERE clause limits which rows get updated. Without it, all rows in the table will be changed.
Click to reveal answer
beginner
Write the basic syntax of an UPDATE statement with a WHERE condition.
UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;
Click to reveal answer
intermediate
What happens if you run UPDATE employees SET salary = 5000; without a WHERE clause?
All rows in the employees table will have their salary set to 5000, which might not be what you want.
Click to reveal answer
beginner
How can you update only the rows where the employee's department is 'Sales'?
Use a WHERE clause to specify the condition: <br>
UPDATE employees SET salary = 6000 WHERE department = 'Sales';
Click to reveal answer
What does the WHERE clause do in an UPDATE statement?
ADeletes rows from the table
BSpecifies new column names
CCreates a new table
DLimits which rows are updated
What happens if you omit the WHERE clause in an UPDATE statement?
AAll rows in the table are updated
BNo rows are updated
COnly one row is updated
DThe table is deleted
Which SQL keyword is used to specify the new values in an UPDATE statement?
AWHERE
BFROM
CSET
DSELECT
How would you update the 'status' column to 'active' only for users with 'id' 10?
ASELECT status FROM users WHERE id = 10;
BUPDATE users SET status = 'active' WHERE id = 10;
CUPDATE users SET status = 'active';
DUPDATE users WHERE id = 10 SET status = 'active';
Which of these is a valid UPDATE statement?
AUPDATE products SET price = 20 WHERE id = 5;
BUPDATE products price = 20 WHERE id = 5;
CUPDATE products SET price 20 WHERE id = 5;
DUPDATE products WHERE id = 5 SET price = 20;
Explain how the UPDATE statement works with a WHERE condition in SQL.
Think about how you tell SQL which rows to change and what to change.
You got /3 concepts.
    Describe what could happen if you forget the WHERE clause in an UPDATE statement.
    Imagine changing every item in a list by mistake.
    You got /3 concepts.