本文总结了在SQL Server,Oracle,MySQL中Update语句多表关联更新的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
在本例中:我们要用表gdqlpj中的gqdltks,bztks字段数据去更新landleveldata中的同字段名的数据,条件是当landleveldata 中的GEO_Code字段值与gdqlpj中的lxqdm字段值相等时进行更新。
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 a set a.gqdltks=b.gqdltks,a.bztks=b.bztks from landleveldata a,gdqlpj b where a.GEO_Code=b.lxqdm
Oracle语法:
UPDATE updatedtable SET (col_name1[,col_name2...])= (SELECT col_name1,[,col_name2...] FROM srctable [WHERE where_definition])
Oracel 示例:
update landleveldata a set (a.gqdltks, a.bztks)= ( b.gqdltks, b.bztks from gdqlpj b where a.GEO_Code=b.lxqdm)
MySQL语法:
UPDATE table_references SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition]
MySQL 示例:
update landleveldata a, gdqlpj b set a.gqdltks= b.gqdltks, a.bztks= b.bztks where a.GEO_Code=b.lxqdm