SQL Update Multi-Table Federated Update method _ database other

Source: Internet
Author: User
Tags sql server example sqlite

There are times when we need to update data from multiple tables and then we need to use the following methods:

(1) SQLite multiple table Update method

Copy Code code 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 that is supported in SQL Server for this syntax SQLite but does not support

SQLite can be converted to the following syntax

Copy Code code 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 multiple table Update method

Copy Code code 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 Code code as follows:

Update a set A.gqdltks=b.gqdltks,a.bztks=b.bztks from
Landleveldata A,GDQLPJ b where a.geo_code=b.lxqdm

Access database Multi-table Update method

Copy Code code as follows:

x = "Update" + DLTB + "A INNER join TBAREA2 B on A.objectid=b.fid set a." + FD_DLTB_XZDWMJ + "=B.AREA_XZDW, A." + Fd_d LTB_LXDWMJ + "=B.AREA_LXDW";
Sqllist.add (x);

(3) Oracle Multi-Table Update method

Oracle Syntax:

Copy Code code as follows:

UPDATE updatedtable SET (col_name1[,col_name2 ...]) = (SELECT
Col_name1,[,col_name2 ...] From srctable [WHERE where_definition])

Oracel Example:

Copy Code code as follows:

Update Landleveldata a set (A.gqdltks, A.bztks) = (select B.gqdltks,
B.bztks from GDQLPJ b where A.GEO_CODE=B.LXQDM)

(4) MySQL multiple table Update method

MySQL Syntax:

Copy Code code as follows:

UPDATE table_references SET col_name1=expr1 [, col_name2=expr2 ...]
[WHERE Where_definition]

MySQL Example:

Copy Code code as follows:

Update Landleveldata A, GDQLPJ b set a.gqdltks= b.gqdltks, a.bztks=
B.bztks where A.GEO_CODE=B.LXQDM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.