update multiple columns sql code example

Example 1: update column sql server

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

Example 2: add multiple columns to table sql

//Example
ALTER TABLE employees
  ADD last_name VARCHAR(50),
      first_name VARCHAR(40);

Example 3: sql update multiple columns from another table

-- Oracle
UPDATE table2 t2 SET (VALUE1, VALUE2) = 
    (SELECT COL1 AS VALUE1, COL1 AS VALUE2 FROM table1 t1 WHERE t1.ID = t2.ID);
-- SQL Server
UPDATE table2 t2 SET
    t2.VALUE1 = t1.COL1,
    t2.VALUE2 = t1.COL2
FROM table1 t1
INNER JOIN t2 ON t1.ID = t2.ID;
-- MySQL
UPDATE table2 t2 INNER JOIN table1 t1 USING (ID)
SET T2.VALUE1 = t1.COL1, t2.VALUE2 = t1.COL2;

Example 4: sql server update multiple columns at once

UPDATE Person.Person
 Set FirstName = 'Kenneth'
    ,LastName =  'Smith'
 WHERE BusinessEntityID = 1

Example 5: update multiple columns in sql

UPDATE table-name SET column-name = value, column-name = value WHERE condition = value

Example 6: update table sql multiple set

-- CANT do multiple sets but can do case
UPDATE table
SET ID = CASE WHEN ID = 2555 THEN 111111259 
              WHEN ID = 2724 THEN 111111261
              WHEN ID = 2021 THEN 111111263
              WHEN ID = 2017 THEN 111111264
         END
WHERE ID IN (2555,2724,2021,2017)