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:
01466973
Vues:
77
I am wondering how you would set off a trigger based on only one column changing? Is this possible? I know you can set a trigger to run if there has been a delete, update or insert based on the table, but how would you narrow this down to one column having changed?

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