Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 triggers

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-10-29 : 22:59:58
marius writes "Hi,
I would like to write a trigger that fires when certain columns in a table are updated or deleted.I read in the BOL but I didn't make it work.Here comes an example:
CREATE TRIGGER my_trig2
ON my_table
FOR INSERT
AS
IF ( COLUMNS_UPDATED() & 2 = 2 )
PRINT 'Column b Modified'
GO

and the table looks like that :
CREATE TABLE my_table
(a int NULL, b int NULL)
GO
The IF COLUMNS_UPDATED() clause can be used to check which columns in a table were updated by an INSERT or UPDATE statement. This clause uses an integer bitmask (2) to specify the columns to test. How can I calculate the bitmask if I have 20 columns to check."
   

- Advertisement -