February 19, 2013 at 2:39 am
Hi I am trying to create a trigger to store an original ordered qty field when the data is inserted into the table. We have several different ways of entering orders onto our system so I thought a simple trigger would be a better solution then altering lots of frontend applications.
It appears that the trigger is copying all rows from the original field into the field I want to keep a history of the original value.
How can I ensure the only row that updates is the row just created, in sql2000?
here is my trigger, thanks jasemilly
UPDATE test
SET col2 = col1
FROM test
February 19, 2013 at 2:53 am
If the code you posted was indeed the entire trigger, then yes, that will update the entire table
UPDATE test
SET col2 = col1
FROM test
Since there's no conditions, no restrictions and nothing to tell SQL otherwise, that's an update of the entire Test table (as it would be if you ran that update anywhere else)
If you want to restrict to the rows affected by the operation that fired the trigger, you need to join or filter based on the inserted and/or deleted pseudotables.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply