How can we update multiple columns at once using the UPDATE statement?

0104

You can update multiple columns at once using the UPDATE statement by specifying each column and its new value, separated by commas. Here’s the syntax:

UPDATE table_name
SET column1 = value1, column2 = value2, column3 = value3
WHERE condition;

Example

Suppose you have a table named employees and you want to update both the department and salary for a specific employee:

UPDATE employees
SET department = 'Marketing', salary = 60000
WHERE employee_id = 1;

In this example, the department and salary columns are updated for the employee with employee_id equal to 1. Make sure to include a WHERE clause to avoid updating all rows in the table.

0 Comments

no data
Be the first to share your comment!