May 4, 2015 at 7:03 am
Is it possible to have a trigger on a single table (column2, column3, column5 & column9) and if so I would have to used the "columns_updated" method.
May 4, 2015 at 7:24 am
kd11 (5/4/2015)
Is it possible to have a trigger on a single table (column2, column3, column5 & column9) and if so I would have to used the "columns_updated" method.
All triggers are on a single table. Now what is the question here?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 4, 2015 at 12:08 pm
Let me re-word that, I want to fire a trigger when column2, column3, column5 and column9 are updated/insert (not the other six columns) so do I need to use the "column_update" statement.
May 4, 2015 at 12:14 pm
kd11 (5/4/2015)
Let me re-word that, I want to fire a trigger when column2, column3, column5 and column9 are updated/insert (not the other six columns) so do I need to use the "column_update" statement.
column_update is very misleading, since it just checks if the column name was included in the DML command, and not whether the values actually changed.
you might need to handle NULLS as well, so this is just to provide an example:
the best way is to check by comparign the INSERTED virtual table to teh DELETED virtual table, on a column basis.
ie
IF EXISTS(SELECT * FROM INSERTED i INNER JOIN DELETED d ON i.PKColumn = d.PKColumn WHERE i.Name <> d.Name OR i.Address1 <> d.Address1)
BEGIN
--log some extra data? send an email? do something
END
Lowell
May 5, 2015 at 2:47 am
kd11 (5/4/2015)
Let me re-word that, I want to fire a trigger when column2, column3, column5 and column9 are updated/insert (not the other six columns) so do I need to use the "column_update" statement.
An insert always affects all columns of a table.
Could you be more specific about what you're trying to do?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply