Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
INSTEAD OF Triggers
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01467449
Message ID:
01467460
Vues:
30
That is a good point, one that had not hit me yet. The UPDATE in the trigger I worked on the other night is limited to one record, so that is okay in that case, but I hear you, in that multiple records coudl be updated.
UPDATE Invoices2
SET PaymentTotal = 503.20
WHERE InvoiceID = 105
>If a single UPDATE statement affects multiple invoice rows, you will only catch the first vendor. (This is a common "mistake" - many people write trigger code with the assumption that the UPDATE statement will only ever affect one row).

>Unless you're 100% certain that an UPDATE will ONLY affect 1 row, always write update triggers with the assumption that multiple rows are being affected. (If you weren't already aware of this...if I type "UPDATE Invoices set Discount = Discount + .1 " , to affect all rows, the trigger fires ONCE and the DELETED/INSERTED tables will contain before/after values for all rows affected by the UPDATE statement).

>So if you're sure that only 1 invoice will EVER get updated at once, then your code above is OK....but if someone were to do a mass update where multiple invoices and multiple vendors were affected, your code would only capture one of the vendors. (And if you had typed out...SET @Vendorname = (select blah blah blah) to capture the vendor that way, it would actually generate an error).
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform