【问题标题】:How to update the each record in sql server如何更新sql server中的每条记录
【发布时间】:2012-09-29 03:30:55
【问题描述】:

我需要使用更新脚本更新表中的每条记录

查询 1:

Select acheivementsId 
from Students 
where student_id = 2

结果:: 61 条记录// acheivementid 的数量

查询 2:

Select acheivementsId 
from Students 
where student_id = 4  

结果:61 条记录// acheivementid 的数量

我需要将 Student_id = 2 acheivementid 更新为 student_id = 4 acheivementId。

如何编写更新61条记录的Update Statement。

谢谢

【问题讨论】:

  • 你已经用 mysql 和 sql-server 标记了这个,你使用的是哪个 RDBMS?
  • 你能告诉我们学生表的结构吗?
  • 每个学生 ID 的所有记录的 acheivementsId 值是否相同?如果不是,记录应该如何排列?
  • acheivementsId 类似于 1 ,2,3,4,5,6,7.. 等等..
  • 明天我将在我的 Sql Server 上进行测试,我会告诉你结果。我已经在 SQLite 上进行了测试,然后去.....可能我还没有理解问题!但是您想将 student_id = 2 的记录的 acheivementsId 值更改为 student_id = 4 的记录的 acheivementsId ... 对吗?所有记录....

标签: mysql sql sql-server sql-server-2008


【解决方案1】:

试试这个:

UPDATE Students 
   SET acheivementsId = (SELECT acheivementsId from Students where Student_id=4) 
WHERE Student_id=2

【讨论】:

  • 那行不通。子选择将返回多行。
猜你喜欢
  • 2010-11-14
  • 1970-01-01
  • 2013-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多