Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Update Triggers


Update Triggers

Author
Message
jason-810420
jason-810420
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 22
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
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47189 Visits: 44356
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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search