Question : Setting a trigger when a specific column is updated?

I have the below trigger which does an update when a table update occurs. I was wondering is it possible to have a similar trigger when a specific field is changed?

For example in the items table I have status and I would like to track when the statuses are changed. So for example if my sword item has inactive status and for whatever reason the status is updated to active I would like to capture that.

Is it possible to adjust the below trigger to handle that?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Create TRIGGER [dbo].[ItemsUpdate] ON [dbo].[Items]
   AFTER Update
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
    insert into ItemsLog(id,name,[date],[function])
	select id,name,getdate(),'Update'
	from inserted

END

Answer : Setting a trigger when a specific column is updated?

only in the code:


Create TRIGGER [dbo].[ItemsUpdate] ON [dbo].[Items]
   AFTER Update
AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
   IF UPDATED(your_columns)
    -- Insert statements for trigger here
    insert into ItemsLog(id,name,[date],[function])
      select id,name,getdate(),'Update'
      from inserted

END
Random Solutions  
 
programming4us programming4us