T-SQL 之 多表联合更新
1、 sqlite 多表更新方法
UPDATE tA SET col1=tB.col1 FROM tableA tA INNER JOIN tableB tB ON tA.col2=tB.col2
这是一个非常简单的批量更新语句 在SqlServer中支持此语法 sqlite中却不支持,sqlite中可转换为如下语法:
UPDATE tableA SET col1=(SELECT col1 FROM tableB WHERE col2=tableA.col2)
2、SQL Server 多表更新方法
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示例:
UPDATE tA SET tA.col1=tB.col1,tA.col2=tB.col2 FROM tableA tA,tableB tB WHERE tA.col3=tB.col3
3、access数据库多表更新方法
x = "update " + DLTB + " a inner join tbarea2 b on a.objectid=b.FID set a." + fd_dltb_xzdwmj + "=b.area_xzdw, a." + fd_dltb_lxdwmj + "=b.area_lxdw"; SQLList.Add(x);
4、Oracle 多表更新方法
UPDATE updatedtable SET (col_name1[,col_name2...])=(SELECT col_name1,[,col_name2...] FROM srctable [WHERE where_definition])
Oracel 示例:
UPDATE tableA tA SET (tA.col1, tA.col2)=(SELECT tB.col1,tB.col2 FROM tableB tB WHERE tA.col3=tB.col4)
5、MySQL 多表更新方法
UPDATE table_references SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition]
MySQL 示例:
UPDATE tableA tA, tableB tB SET tA.col1=tB.col1, tA.col2=tB.col2 WHERE tA.col3=tB.col4