wish helps you Use this. For more information about triggers refer this link.
CREATE TRIGGER Sample ON [dbo].[FileContent]
DECLARE @nFieldID AS INT
SELECT @nFieldID = [FileId] FROM INSERTED
SET [UpdateTime] = GETDATE()
WHERE [FileId] = @nFieldID
Update a table when an specific column of another table is updated using trigger in SQL Server
hope this fix your issue I have a table with the following columns: , thanks to Mr. Bhosale
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE TRIGGER [dbo].[updateLM_TIME]
AFTER INSERT, UPDATE
IF NOT UPDATE(CLIENT_SYNCED_TIME)
SET lm_time = CONVERT(DATETIME, CONVERT(VARCHAR(20), GETDATE(), 120))
WHERE ID IN (SELECT DISTINCT ID FROM Inserted)
How to add a trigger if column has updated with specific string
hop of those help? I want to add a trigger if name has update with "NEW_" string. Below is my current trigger but its working without checking the updated value contain "NEW_" . please advice , Use this:
CREATE TRIGGER update_user_deleted_date BEFORE UPDATE ON users
FOR EACH ROW BEGIN
IF (LOCATE('NEW_', NEW.name) != 0) THEN
SET NEW.date_deleted = NOW();
fire after update trigger if the updated column value is equal to 'APPROVED'
I wish did fix the issue. You can't control whether the trigger will be fired or not, but you can control what will happen inside the trigger. You should be aware that triggers are fired based on statements, not on rows, so be careful not to assume the inserted table will only contain one row.
CREATE TRIGGER dbo.tr_Test ON dbo.Test FOR UPDATE
INSERT INTO test_audit (Id, Name, [Status], [time stamp])
SELECT Id, Name, [Status], GETDATE()
FROM Inserted I
WHERE I.[Status] = 'APPROVED'
FROM Deleted D
WHERE D.Id = I.Id -- assuming primary key column is called id...
AND D.[Status] <> 'APPROVED'