Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较SQL Server 2012中的两个表_Sql_Sql Server 2012 - Fatal编程技术网

比较SQL Server 2012中的两个表

比较SQL Server 2012中的两个表,sql,sql-server-2012,Sql,Sql Server 2012,如果我有两个表Grades和StudentsMark,如下所示: 表等级 StudentId Mark examId --------------------------- 1 10 1 2 9 2 3 15 1 4 26 3 表学生分数: StudentId Mark examid -----------------------

如果我有两个表
Grades
StudentsMark
,如下所示:

等级

StudentId    Mark    examId 
---------------------------
1              10     1
2              9      2
3              15     1
4              26     3
学生分数

StudentId    Mark     examid
-----------------------------
1              10      1
2              5       2
3              15      1
4              8       3
我想比较这两个表之间的数据,如果分数不同,我想用
StudentMark(mark)
替换
grade(mark)


如何做到这一点?

使用
更新
连接,并通过在
WHERE
子句中选中它,只更新一个不同的

查询

update t1
set t1.[Mark] = t2.[Mark]
from [grade] t1
join [StudentMark] t2
on t1.[StudentId] = t2.[StudentId]
where t1.[Mark] <> t2.[Mark];
更新t1
设置t1.[Mark]=t2.[Mark]
从[等级]t1开始
加入[StudentMark]t2
在t1上。[StudentId]=t2。[StudentId]
式中t1.[Mark]t2.[Mark];

您可以发布您尝试过的内容吗?我使用大容量插入将值从文件插入studentsMark表,现在我想使用大容量插入更新值update@Moh您不需要使用批量更新。您只需在insert语句后更新即可。@plaidDK我知道,但我的培训师让我使用it@Moh你也可以说这是一种散装货,因为它是在每个学生身上连接起来的。