【SQL】sql update 多表关联更新方法总结
#表结构:
1、表一:Test1
| Id | name | age |
| 1 | ||
| 2 |
2、表二:Test2
| Id | name | age |
| 1 | 小明 | 10 |
| 2 | 小红 | 8 |
#实现将表Test2的name和age字段数据更新到表Test1中,按照id相等的条件
1、SQLServer多表更新方法:
语法:
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 ] ) ]
例子:
update test1
set test1.name=test2.name,test1.age=test2.age
from test1
inner join test2
on test1.id=test2.id
2、Oracle 多表更新方法:
语法:
UPDATE updatedtable
SET (col_name1[,col_name2...])= (SELECT col_name1,[,col_name2...]
FROM srctable [WHERE where_definition])
例子:
update test1
set (test1.name,test1.age)=
(select test2.name,test2.age from test2 where test2.id=test1.id)
3、MySql多表更新方法:
语法:
UPDATE table_references
SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition]
例子:
update test1,test2
set test1.name=test2.name,test1.age=test2.age
where test1.id=test2.id
4、通用方法:(*^__^*)
update test1
set name=(select name from test2 where test2.id=test1.id),
age=(select age from test2 where test2.id=test1.id)
———————————————————————————————————————————————————
【SQL】sql update 多表关联更新方法总结的更多相关文章
- Oracle\MS SQL Server Update多表关联更新
原文:Oracle\MS SQL Server Update多表关联更新 一条Update更新语句是不能更新多张表的,除非使用触发器隐含更新.而表的更新操作中,在很多情况下需要在表达式中引用要更新的表 ...
- MSSQL update 多表关联更新
update tMeter set 字段= t.源自段 from ( select * from 源表信息 ) t where 关联条件 实际demo: UPDATE dbo.WX_TWODIMENC ...
- mysql update 多表关联更新
UPDATE new_schedules_spider_static_schedule s join new_scac_port p on p.`PORT` = s.`PORT` and p.SCAC ...
- 书写 sql 中关于 update 多表联合更新的方法
SQL Update多表联合更新的方法(1) sqlite 多表更新方法//----------------------------------update t1 set col1=t2.col1fr ...
- 170823、SQL Update多表联合更新的方法
SQL Update多表联合更新的方法 (1) sqlite 多表更新方法 update t1 set col1=t2.col1 from table1 t1 inner join table2 t2 ...
- SQL Update多表联合更新的方法
SQL Update多表联合更新的方法 (1) sqlite 多表更新方法 update t1 set col1=t2.col1 from table1 t1 inner join table2 t2 ...
- MySQL 多表关联更新及删除
目录: <MySQL中的两种临时表> <MySQL 多表关联更新及删除> <mysql查询优化之三:查询优化器提示(hint)> 一. 多表关联更新 问题 ...
- 数据库MySQL中关于“多表关联更新”的那些事
在常见的sql中,我们经常在查询中进行多表关联查询,用的比较熟练.今天在开发中遇到一个实际业务场景是多表关联更新,一时不知所措.本着多学习的态度,没有直接写java代码去实现,终于把多表关联更新的sq ...
- Oracle SQL性能优化 - 根据大表关联更新小表
需求: 小表数据量20w条左右,大表数据量在4kw条左右,需要根据大表筛选出150w条左右的数据并关联更新小表中5k左右的数据. 性能问题: 对筛选条件中涉及的字段加index后,如下常规的updat ...
随机推荐
- scala简单入门_wordCount
scala的语法写起来是非常的舒服的,相比java来说,简便许多.而Java在scala面前就显的略微有些笨重了. 接下来我们看一下scala版的wordcount import scala.io.S ...
- js .map方法
map这里的map不是“地图”的意思,而是指“映射”.[].map(); 基本用法跟forEach方法类似: array.map(callback,[ thisObject]); callback的参 ...
- 每个JavaScript工程师都应懂的33个概念
摘要: 基础很重要啊! 原文:33 concepts every JavaScript developer should know 译文:每个 JavaScript 工程师都应懂的33个概念 作者:s ...
- Python全栈学习_day010作业
1,继续整理函数相关知识点,写博客. 2,写函数,接收n个数字,求这些参数数字的和.(动态传参)def MySum(*args): sum = 0 for i in range(len(args)): ...
- importToMbtiles
import sqlite3, sys, logging, time, os, json, zlib, re ''' MapDBImporter-latest -f png -mName " ...
- 安卓开发_深入理解Handler消息传递机制
一.概述 因为子线程的run()方法无法修改UI线程(主线程)的UI界面,所以Android引入了Handler消息传递机制,实现在新创建的线程中操作UI界面 二.消息类(Message) 消息类是存 ...
- OkHttp3源码详解(二) 整体流程
1.简单使用 同步: @Override public Response execute() throws IOException { synchronized (this) { if (execut ...
- [20171110]_allow_read_only_corruption参数.txt
[20171110]_allow_read_only_corruption参数.txt --//昨天在修改查询隐含参数脚本时发现一个参数_allow_read_only_corruption,感觉应该 ...
- 转 让Python在Android系统上飞一会儿
让Python在Android系统上飞一会儿 地址: http://blog.csdn.net/ccwwff/article/details/6208260
- VsCode 的使用
一.简介 VsCode(Visual Studio Code),官网地址:https://code.visualstudio.com/ Visual Studio Code is a lightwei ...