SQL UPDATE實現多表更新

SQL UPDATE實現多表更新html

from:http://bbs.chinabyte.com/thread-347169-1-1.html 在開發中,數據庫來回換,而有些關鍵性的語法又各不相同,這是一件讓開發人員很頭痛的事情.本文總結了Update語句更新多表時在SQL Server,Oracle,MySQL三種數據庫中的用法.我也試了SQLite數據庫,都沒成功,不知是不支持多表更新仍是咋的. 在本例中: 咱們要用表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.lxqdmsql

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)= (select 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.lxqdmexpress

有A、B張表,其記錄以下: A表 c1 c2

1 a1 2 a2 3 a3 8 a8 B表 c1 c3

1 b1 2 b1 3 b3 10 b10 A.c1與B.c1相等,用一條sql語句,實現A.c2的值更新爲B.c3

UPDATE A SET A.c2 =B.c3 from A ,B where A.c1=B.c1 UPDATE A SET A.c2 =B.c3 from A inner join B on A.c1=B.c1 注意:update後面是不能跟多表的,但跟在from子句後面ui

相關文章
相關標籤/搜索