51代码网ORACLEMYSQLSQL SERVER其它数据库java/jspasp/asp.netC/C++/VC++APP应用其它语言服务器应用
您现在的位置: 51代码网 >> sqlserver >> 文章正文

怎么快速的将ScoreB中的SCORE加到student表对应的项中

更新时间:2013-6-11:  来源:51代码网

怎么快速的将ScoreB中的SCORE加到student表对应的项中

有表 Student 结构和数据如下:
编号    总分数
ID SCORE
1 50
2 30
3 20
4 50
5 10

表 ScoreB (某科目分数)
Student.ID FK   科目的分数
StudentID SOCRE
1 10
2 30
3 20
4 20

怎么快速的将ScoreB中的SCORE加到student表对应的项中
比如说执行后。ScoreB.StudentID为1的分数(10)加到Student.ID为1的里面,并且更新Student

我用的是游标,有好几万条数据,更新频繁的话 sqlserver.exe占很大的内存。所以看大家有没有更好的办法。。

update Student set SROE=SROE+(select SROE_2 from Student_2 where id=id_2)
where id in(select id_2 from Student_2)

update student set score=score+b.score from ScoreB b
where student.id=b.id

  • 上一篇文章:
  • 下一篇文章: 没有了
  • 赞助商链接
    推荐文章
  • 此栏目下没有推荐文章
  • {
    设为首页 | 加入收藏 | 友情链接 | 网站地图 | 联系站长 |