0
0
SQLquery~5 mins

UPDATE with expressions in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL UPDATE statement do?
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
How can you use expressions in an UPDATE statement?
You can use expressions to calculate new values based on existing column values, like adding 10 to a salary: SET salary = salary + 10.
Click to reveal answer
beginner
Example: What does this SQL do? <br>UPDATE employees SET salary = salary * 1.05 WHERE department = 'Sales';
It increases the salary by 5% for all employees in the Sales department.
Click to reveal answer
intermediate
Can you use functions in UPDATE expressions? Give an example.
Yes, you can use functions. For example, to set a date column to the current date: UPDATE orders SET shipped_date = CURRENT_DATE WHERE shipped_date IS NULL;
Click to reveal answer
beginner
Why is it important to use a WHERE clause in an UPDATE statement with expressions?
Without a WHERE clause, the UPDATE will change all rows in the table, which might cause unintended data changes.
Click to reveal answer
What happens if you run an UPDATE statement without a WHERE clause?
AOnly the first row is updated
BNo rows are updated
CAll rows in the table are updated
DThe statement will cause an error
Which of the following is a valid expression in an UPDATE statement?
ASET price = price - 'ten'
BSET price = price + 10
CSET price = price & 10
DSET price = 'price + 10'
How do you increase a numeric column 'score' by 20% using UPDATE?
ASET score = score * 1.2
BSET score = score + 20
CSET score = score / 1.2
DSET score = score - 20
Which SQL function can you use to set a date column to today’s date in an UPDATE?
ACURRENT_DATE
BNOW()
CGETDATE()
DTODAY()
What does this statement do? <br>UPDATE products SET stock = stock - 1 WHERE product_id = 100;
ADeletes product 100
BSets stock to 1 for product 100
CIncreases stock by 1 for product 100
DDecreases stock by 1 for product 100
Explain how to use expressions in an UPDATE statement to modify data.
Think about changing values based on current data.
You got /4 concepts.
    Describe why the WHERE clause is important in UPDATE statements with expressions.
    Consider what happens if you forget WHERE.
    You got /4 concepts.