Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Server 7.0 Triggers
Message
From
14/03/2000 00:48:14
 
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00344975
Message ID:
00345229
Views:
19
The new values can be accessed via the inserted table ("inserted" is a reserved word in SQL Server and stores
the new/updated records).

The old values can be accessed via the original table. The trigger is fired just before the changes are applied, so the
target table(s) contain the old values.

The following will give you the difference between the old and new values for all modified records:
SELECT old.pk, new.value - old.value AS difference
FROM inserted AS new
INNER JOIN mytable AS old
ON new.pk = new.pk

Here are some gotchas when working with triggers:
- The inserted and deleted special tables contain more than one record if the original sql command modified more
than one record (I don't know why but most people think that they contain only one record and that the trigger
will fire for each record).
- The UPDATED(column) function returns true when the column was included in the original sql, not when the
column was actually modified (so, the checking against the old values has to be done anyway).
- The trigger fires even if the SQL command is applied to no records. This means any column in inserted/deleted
may be null.

Vlad

>Does anyone know if it's easy to reference both old and new field values via triggers in SQL Server 7.0. e.g. If I was amending a balance detail record and changing the ordered quantity from 10 to 20, I would would want to update the ordered quantity on the balance header record by the (current header value + (new detail value - old detail value)) hence I would need to know what the new and old balance detail ordered quantities were. Thanks.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform