Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can you set off a trigger based on one column changing?
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01466971
Message ID:
01466975
Vues:
59
If the Invoices.PaymentTotal column changes during an update, I wanted the trigger to detect the change and then copy the Vendor's Name, and Address to another table from the Vendors table for the vendor for that same invoice.

>With triggers, I don't believe you can.

>Closest you can do is the following....suppose you want to detect if ProductMaster.ListPrice has changed...
DECLARE @NumRowsChangedByUpdate int

SET @NumRowsChangedByUpdate = 
    (select  Count(ProductMaster.ProductKey) from ProductMaster
                                         JOIN Inserted on ProductMaster.ProductKey = Inserted.ProductKey
                                         join Deleted on ProductMaster.ProductKey = Deleted.ProductKey
                                                where Inserted.ListPrice <> Deleted.ListPrice)

if @NumRowsChangedByUpdate > 0
          -- then go do something
However, if you're using Change Data Capture, you could theoretically tap into something using CDC if you set it up for just a single column, though it's going to involve some work.

What specifically do you want to do when the single column value changes?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform