1

I have a table that have 1 row table 1

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

and i Want update this row so I created i stored procedure

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

but the result of the excution of Stored Procedure generate another row

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

So please where is the problem? Thank you in advance.

Stored procedure is:

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
M.Ali
  • 67,945
  • 13
  • 101
  • 127
dba2015
  • 127
  • 1
  • 4
  • 13
  • No, an `update` does never create a new record. An `insert` does. – juergen d May 24 '15 at 10:15
  • Check the stored procedure or if there's a trigger on the table. – DavidG May 24 '15 at 10:23
  • 1
    Can you show the stored procedure definition? – M.Ali May 24 '15 at 10:26
  • @DavidG how can I determine if a trigger existe or not when I execute my stored procedure? – dba2015 May 24 '15 at 11:29
  • @M.Ali `code`/****** Object: StoredProcedure [dbo].[update_score] Script Date: 05/24/2015 13:30:30 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER proc [dbo].[update_score] @id_employee int, @score int, @nbr_month int, @month int, @year int as begin update table 1 set score=@score,nbr_month=@nbr_month where id_employee=id_employee and month=@month and year=@year end `code` – dba2015 May 24 '15 at 11:35
  • 1
    http://stackoverflow.com/questions/4305691/need-to-list-all-triggers-in-sql-server-database-with-table-name-and-tables-sch – DavidG May 24 '15 at 11:51

2 Answers2

1

That is not possible. Update modifies already existing records. So your code might be running an insert command. Or calling a stored procedure which does the same. Or a trigger is triggered. But certainly, the update will not generate new records.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
0

There might be update Trigger written on table.thats the only way otherwise it couldn't.