Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Update Triggers Expand / Collapse
Author
Message
Posted Tuesday, February 19, 2013 2:39 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, February 19, 2013 2:39 AM
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
Post #1421493
Posted Tuesday, February 19, 2013 2:53 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 9:44 AM
Points: 42,822, Visits: 35,953
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 2008, MVP
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

Post #1421498
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse