0
0
SQLquery~5 mins

UPDATE multiple columns 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 meet a specified condition.
Click to reveal answer
beginner
How do you update multiple columns in a single SQL UPDATE statement?
You list each column and its new value separated by commas after the SET keyword, like: SET column1 = value1, column2 = value2.
Click to reveal answer
beginner
Why should you always include a WHERE clause in an UPDATE statement?
Without a WHERE clause, the UPDATE will change all rows in the table, which might cause unintended data loss or errors.
Click to reveal answer
beginner
Example: Update the 'name' to 'Alice' and 'age' to 30 for the user with id 5. Write the SQL query.
UPDATE users SET name = 'Alice', age = 30 WHERE id = 5;
Click to reveal answer
beginner
Can you update columns to NULL using UPDATE? How?
Yes, you can set a column to NULL by assigning NULL as the value, for example: SET column_name = NULL.
Click to reveal answer
Which keyword is used to specify the columns to update in an SQL UPDATE statement?
AFROM
BSET
CWHERE
DSELECT
What happens if you omit the WHERE clause in an UPDATE statement?
AThe query will fail
BNo rows are updated
COnly one row is updated
DAll rows in the table are updated
How do you update two columns 'price' and 'stock' in one UPDATE statement?
ASET price = 10, stock = 5
BSET price = 10 AND stock = 5
CWHERE price = 10, stock = 5
DUPDATE price = 10, stock = 5
Which of these is a valid UPDATE statement to change 'status' to 'active' and 'score' to 100 for user_id 7?
AUPDATE users SET status = 'active', score = 100 WHERE user_id = 7;
BUPDATE users SET status = 'active' AND score = 100 WHERE user_id = 7;
CUPDATE users WHERE user_id = 7 SET status = 'active', score = 100;
DUPDATE users SET status = 'active' score = 100 WHERE user_id = 7;
Can you update a column to NULL in SQL?
AOnly if the column is a number
BNo, NULL is not allowed in UPDATE
CYes, by setting column = NULL
DOnly if the column is a string
Explain how to update multiple columns in a SQL table and why the WHERE clause is important.
Think about changing more than one detail at once and controlling which rows change.
You got /3 concepts.
    Write an example SQL UPDATE statement that changes two columns for a specific row.
    Use a simple table like users and columns like name and age.
    You got /3 concepts.