Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update date to a current date in the event of value chan
Message
De
16/06/2010 10:09:51
 
 
À
16/06/2010 10:08:04
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
01469101
Message ID:
01469224
Vues:
24
I appreciate it.
Thank you

>Here's the code for an update trigger, using your table and column names. (You'll need to change the reference of "primaryKey" to the name of your primary key column in your inventory table)
>
>Note that the trigger exposes two system tables from the transaction log...DELETED (which contains the row or rows updated to begin with, BEFORE the update), and INSERTED (which contains the row or rows updated, AFTER the update). You join them together, and in the WHERE clause, only use those where the standard cost column has changed. Let me know if this helps...
>
>So yes, you CAN create a trigger on a table, and inside the trigger, update the very table that caused the trigger to fire (and by default, it WON'T "re-fire" the trigger recursively)
>
>
>
>
>CREATE TRIGGER Inventory_Update_Trigger
>ON Inventory
>AFTER UPDATE
>
>AS
>
>BEGIN
>
>   UPDATE Inventory 
>                 SET dStndCost = GETDATE()
>                     FROM Inventory
>                           JOIN Inserted on Inventory.PrimaryKey = Inserted.PrimaryKey
>                           JOIN Deleted on Inventory.PrimaryKey = Deleted.PrimaryKey
>                                  WHERE Inserted.nStndCost <> Deleted.nStndCost
>END
>GO
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform