Sometimes we need to update the data in multiple tables at the same time, so we need to use the following method:
(1) SQLite multi-table update method
Copy the codeThe code is as follows:
//----------------------------------
update t1 set col1=t2.col1
from table1 t1
inner join table2 t2 on t1.col2=t2.col2
This is a very simple batch update statement. This syntax is supported in SqlServer but not in sqlite.
sqlite can be converted to the following syntax
Copy the codeThe code is as follows:
update table1 set col1=(select col1 from table2 where col2=table1.col2)
update ta_jbnt_tzhd_pht_Area_xiang set t1=(select sys_xzqhdm.name from sys_xzqhdm
where t2=sys_xzqhdm.code)
(2) SQL Server multi-table update method
Copy the codeThe code is as follows:
//----------------------------------
SQL Server Syntax:UPDATE { table_name WITH ( < table_hint_limited > [ ...n ] ) |
view_name | rowset_function_limited } SET { column_name = { expression | DEFAULT
| NULL } | @variable = expression | @variable = column = expression } [ ,...n ]
{ { [ FROM { < table_source > } [ ,...n ] ] [ WHERE < search_condition > ] } | [
WHERE CURRENT OF { { [ GLOBAL ] cursor_name } | cursor_variable_name } ] } [
OPTION ( < query_hint > [ ,...n ] ) ]
SQL Server Example:
Copy the codeThe code is as follows:
update a set =,= from
landleveldata a,gdqlpj b where a.GEO_Code=
Access database multi-table update method
Copy the codeThe code is as follows:
x = "update " + DLTB + " a inner join tbarea2 b on = set a." + fd_dltb_xzdwmj + "=b.area_xzdw, a." + fd_dltb_lxdwmj + "=b.area_lxdw";
(x);
(3) Oracle multi-table update method
Oracle Syntax:
Copy the codeThe code is as follows:
UPDATE updatedtable SET (col_name1[,col_name2...])= (SELECT
col_name1,[,col_name2...] FROM srctable [WHERE where_definition])
Oracle Example:
Copy the codeThe code is as follows:
update landleveldata a set (, )= (select ,
from gdqlpj b where a.GEO_Code=)
(4) MySQL multi-table update method
MySQL syntax:
Copy the codeThe code is as follows:
UPDATE table_references SET col_name1=expr1 [, col_name2=expr2 ...]
[WHERE where_definition]
MySQL example:
Copy the codeThe code is as follows:
update landleveldata a, gdqlpj b set = , =
where a.GEO_Code=