Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL UPDATE statement affects more records than select statement

The following is driving me nuts, please help me!

As a check before running an UPDATE statement (T-SQL; SQL Server 2012) I run:

select  * 
from Treatment_Day42 
where td42pinit = 'J M' and td42pid = 'ADA';

and I get 1 row returned, as I expect.

However, running

update Treatment_Day42 set td42pid = 'ADA252' 
where td42pinit = 'J M' and td42pid = 'ADA';

affects four records, not one as in the select statement with the exact same WHERE clause. I get the row returned by the select plus 3 other rows where td42pid = ADA458, ADA671 and ADA658.

Why is the UPDATE affecting more rows than I intend it to?

Thanks.

Clemens

like image 241
user3726118 Avatar asked Nov 21 '25 03:11

user3726118


1 Answers

A trigger on the table could do this. Have you checked for an existing trigger?

like image 101
Randy Minder Avatar answered Nov 22 '25 18:11

Randy Minder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!