【问题标题】:Update generate two rows更新生成两行
【发布时间】:2015-08-05 23:45:42
【问题描述】:

我有一个有 1 行的表 表一

____________________________________________
id_employee | month| year| score| nbr_month|
____________________________________________
14          |  2   |2015 | 15   | 4        |
____________________________________________

我想更新这一行 所以我创建了我的存储过程

update table 1
set score=10,nbr_month=4
where id_employee=14 and month=2 and year=2015

但是存储过程的执行结果又生成了一行

____________________________________________
id_employee | month| year| score| nbr_month|
____________________________________________
14          |  2   |2015 | 15   | 4        |
14          |  2   |2015 | 10   | 4        |
____________________________________________

请问问题出在哪里? 提前谢谢你。

存储过程是:

ALTER proc [dbo].[update_score] 
 @id_employee int, 
 @score int, 
 @nbr_month int, 
 @month int, 
 @year int 
as 
begin 
  update table1 
   set score = @score
      ,nbr_month = @nbr_month 
   where id_employee = id_employee 
     and [month] = @month 
     and [year]  = @year 
end

【问题讨论】:

  • 不,update 永远不会创建新记录。 insert 确实如此。
  • 检查存储过程或者表上是否有触发器。
  • 你能显示存储过程的定义吗?
  • @DavidG 执行存储过程时如何确定触发器是否存在?

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


【解决方案1】:

可能有更新触发器写在表上。这是唯一的方法,否则它不能。

【讨论】:

    【解决方案2】:

    这是不可能的。更新修改已经存在的记录。因此,您的代码可能正在运行 insert 命令。或调用执行相同操作的存储过程。或触发trigger。但可以肯定的是,update 不会生成新记录。

    【讨论】:

      猜你喜欢
      • 2015-05-21
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 2021-08-05
      • 2012-08-27
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      相关资源
      最近更新 更多