The basic syntax for the After Update trigger in TSQL is:
CREATE TRIGGER [dbo].[triggerName]
ON [dbo].[Table]
AFTER UPDATE, INSERT
AS BEGIN
SET NOCOUNT ON;
IF UPDATE (ColumnA)
begin
UPDATE Table
SET ColumnC = ColumnA + ColumnB
end
IF UPDATE (ColumnB)
begin
UPDATE Table
SET ColumnC = ColumnA + ColumnB
end
END
Now the above may work, I think, but is it possible to combine both IF UPDATES in one: Something like this:
IF UPDATE (ColumnA) OR (ColumnB)
begin
UPDATE Table
SET ColumnC = ColumnA + ColumnB
end
Of course, you could use the computed column, but out of curiosity I would like to know if you can check for updates on several columns at once in the trigger, and then modify the update trigger.
source
share