3

When I do this in SQL Server

update table 
set column = @value
where id in (1,2,2)

how many updates will perform? 2 or 3, where two updates on row which id=2?

4
  • Why not just test it?
    – Eiko
    Jun 9, 2016 at 7:46
  • Ok, I have it, it's simple... Jun 9, 2016 at 7:47
  • You can post the testcode and result as an answer and accept it later as reference for yourself and others. :)
    – Eiko
    Jun 9, 2016 at 7:48
  • if id is a primary key and the only primairt ket then 2.. else who knows?
    – lordkain
    Jun 9, 2016 at 7:53

2 Answers 2

2

Test your code with a select. and you will see how many rows will be updated.

for the count

select count(*) from table
where id in (1,2,2)

To see the rows being updated

select * from table
where id in (1,2,2)

if id is a primairy key (and the only one, 2 rows )

1
declare @table table (id int, num int)
insert into @table values (1,1),(2,1)

update @table
set num = num + 1
where id in (1,2,2)

select * from @table

Result is:

id  num
1   2
2   2

So, update will perform one time on every unique value from set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.