1-- Oracle
2UPDATE table2 t2 SET (VALUE1, VALUE2) =
3 (SELECT COL1 AS VALUE1, COL1 AS VALUE2 FROM table1 t1 WHERE t1.ID = t2.ID);
4-- SQL Server
5UPDATE table2 t2 SET
6 t2.VALUE1 = t1.COL1,
7 t2.VALUE2 = t1.COL2
8FROM table1 t1
9INNER JOIN t2 ON t1.ID = t2.ID;
10-- MySQL
11UPDATE table2 t2 INNER JOIN table1 t1 USING (ID)
12SET T2.VALUE1 = t1.COL1, t2.VALUE2 = t1.COL2;
1UPDATE table-name SET column-name = value, column-name = value WHERE condition = value
1UPDATE Person.Person
2 Set FirstName = 'Kenneth'
3 ,LastName = 'Smith'
4 WHERE BusinessEntityID = 1
1-- CANT do multiple sets but can do case
2UPDATE table
3SET ID = CASE WHEN ID = 2555 THEN 111111259
4 WHEN ID = 2724 THEN 111111261
5 WHEN ID = 2021 THEN 111111263
6 WHEN ID = 2017 THEN 111111264
7 END
8WHERE ID IN (2555,2724,2021,2017)
9
1UPDATE table_name SET column1 = value1, column2 = value2,...
2WHERE condition;
3
4table_name: name of the table
5column1: name of first , second, third column....
6value1: new value for first, second, third column....
7condition: condition to select the rows for which the
8values of columns needs to be updated.
1/*You can't update multiple tables in one statement,
2however, you can use a transaction to make sure that
3two UPDATE statements are treated atomically.
4You can also batch them to avoid a round trip.*/
5
6
7BEGIN TRANSACTION;
8
9UPDATE Table1
10 SET Table1.LastName = 'DR. XXXXXX'
11FROM Table1 T1, Table2 T2
12WHERE T1.id = T2.id
13and T1.id = '011008';
14
15UPDATE Table2
16SET Table2.WAprrs = 'start,stop'
17FROM Table1 T1, Table2 T2
18WHERE T1.id = T2.id
19and T1.id = '011008';
20
21COMMIT;
22